Mercurial > dotfiles
annotate unixSoft/bin/hgimp @ 431:87a66e293d27
hgrc: set ui.interface to text to avoid any use of curses
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 28 Apr 2017 14:52:49 -0400 |
parents | 24d75bc4a3a1 |
children | 957632211aa3 |
rev | line source |
---|---|
343
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 import argparse |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
3 import os |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
4 import subprocess |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 import sys |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
6 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
7 _MAP = { |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
8 'hg': '~/Programming/hg/crew', |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 'hgsubversion': '~/Programming/hg/hgsubversion', |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 'hg-git': '~/Programming/hg/hg-git', |
364
2ac43cd7bbf7
hgimp: add location of topic repo
Augie Fackler <raf@durin42.com>
parents:
343
diff
changeset
|
11 'topics': '~/Programming/hg/topic', |
343
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
12 } |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
13 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
14 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
15 def main(argv): |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 p = argparse.ArgumentParser('import patches') |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 p.add_argument('repo', type=str, nargs=1, |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 help='repo name to apply patches to') |
391
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
19 p.add_argument('--partial', action='store_true', |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
20 help='Commit partially-applied patches.') |
343
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 args = p.parse_args(argv[1:]) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 name, = args.repo |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 if name in _MAP: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 repo = _MAP[name] |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
25 else: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
26 c = [] |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
27 for n in _MAP: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
28 if n.startswith(name): |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
29 c.append(n) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
30 if not c: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
31 print 'abort: no repo named %s' % name |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
32 sys.exit(1) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
33 elif len(c) != 1: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
34 print 'abort: ambiguous repo name %s matches %s' % ( |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
35 name, ', '.join(c)) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
36 sys.exit(1) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
37 repo = _MAP[c[0]] |
391
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
38 importargs = ['hg', '-R', repo, 'import', '--obsolete'] |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
39 if args.partial: |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
40 importargs.append('--partial') |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
41 importargs.append('-') |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
42 hg = subprocess.Popen(importargs, stdin=subprocess.PIPE) |
343
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
43 hg.stdin.write(sys.stdin.read()) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
44 hg.stdin.close() |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
45 hg.wait() |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
46 sys.exit(hg.returncode) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
47 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
48 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
49 if __name__ == '__main__': |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
50 main(argv=sys.argv) |