Mercurial > dotfiles
annotate unixSoft/bin/hgimp @ 378:20e47bc8eea9
hgrc: disable hg-git and hgsubversion
It hasn't been common for me to use either of these extensions for
some time, so just drop both of them from the main hgrc. Instead I'll
enable them as-needed in individual repositories.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Thu, 09 Jun 2011 20:20:04 -0500 |
parents | 2ac43cd7bbf7 |
children | 24d75bc4a3a1 |
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') |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
19 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
|
20 name, = args.repo |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 if name in _MAP: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 repo = _MAP[name] |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 else: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 c = [] |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
25 for n in _MAP: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
26 if n.startswith(name): |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
27 c.append(n) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
28 if not c: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
29 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
|
30 sys.exit(1) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
31 elif len(c) != 1: |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
32 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
|
33 name, ', '.join(c)) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
34 sys.exit(1) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
35 repo = _MAP[c[0]] |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
36 hg = subprocess.Popen(['hg', '-R', repo, 'import', '--obsolete', '-'], |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
37 stdin=subprocess.PIPE) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
38 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
|
39 hg.stdin.close() |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
40 hg.wait() |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
41 sys.exit(hg.returncode) |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
42 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
43 |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
44 if __name__ == '__main__': |
70e76c545606
hgimp: utility to make importing hg patches from mutt easier
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
45 main(argv=sys.argv) |