Mercurial > dotfiles
annotate unixSoft/bin/hgimp @ 483:9fd2345d35e0
hg: clean up extensions list
Lots of these are obsolete, or I just don't use anymore.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Tue, 07 Jan 2020 16:53:15 -0500 |
parents | 957632211aa3 |
children | 6cc5a0550281 |
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', |
444 | 9 'hglib': '~/Programming/hg/python-hglib', |
343
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 'hgsubversion': '~/Programming/hg/hgsubversion', |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
11 'hg-git': '~/Programming/hg/hg-git', |
364
2ac43cd7bbf7
hgimp: add location of topic repo
Augie Fackler <raf@durin42.com>
parents:
343
diff
changeset
|
12 'topics': '~/Programming/hg/topic', |
343
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 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 def main(argv): |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 p = argparse.ArgumentParser('import patches') |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 name, = args.repo |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 if name in _MAP: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
25 repo = _MAP[name] |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
26 else: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
27 c = [] |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
28 for n in _MAP: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
29 if n.startswith(name): |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
30 c.append(n) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
31 if not c: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
32 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
|
33 sys.exit(1) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
34 elif len(c) != 1: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
35 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
|
36 name, ', '.join(c)) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
37 sys.exit(1) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
38 repo = _MAP[c[0]] |
391
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
39 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
|
40 if args.partial: |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
41 importargs.append('--partial') |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
42 importargs.append('-') |
24d75bc4a3a1
hgimp: add support for using --partial on imported patches
Augie Fackler <raf@durin42.com>
parents:
364
diff
changeset
|
43 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
|
44 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
|
45 hg.stdin.close() |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
46 hg.wait() |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
47 sys.exit(hg.returncode) |
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 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
50 if __name__ == '__main__': |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
51 main(argv=sys.argv) |