Mercurial > hg > hq
annotate hq/main.py @ 2:dedf4c4c2ba2
add a function to list files (incomplete)
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 25 May 2010 10:52:06 -0700 |
parents | 67e06ca7c56e |
children | 8bc27dbf0214 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 """ | |
3 mercurial queue extension front-end policy manager | |
4 """ | |
5 | |
6 import os | |
7 import subprocess | |
8 import sys | |
9 | |
10 from command import CommandParser | |
11 | |
12 def call(command, *args, **kw): | |
13 code = subprocess.call(command, *args, **kw) | |
14 if code: | |
15 if isinstance(command, basestring): | |
16 cmdstr = command | |
17 else: | |
18 cmdstr = ' '.join(command) | |
19 raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) | |
20 | |
21 class HQ(object): | |
22 """ | |
23 mercurial queue extension front-end policy manager | |
24 """ | |
25 | |
26 def __init__(self, parser, options): | |
27 """initialize global options""" | |
28 # TODO: look at hgrc file | |
1 | 29 # for [defaults] repository_host |
0 | 30 |
31 def clone(self, repo, patch=None): | |
32 """clone the repository and begin a patch queue""" | |
33 directory = repo.rsplit('/', 1) | |
34 call(['hg', 'clone', repo, directory]) | |
35 os.chdir(directory) | |
36 call(['hg', 'qinit', '-c']) | |
37 if patch: | |
38 call(['hg', 'qnew', patch]) | |
39 | |
40 def edit(self, patch=None): | |
41 """ | |
42 edit a patch | |
43 - patch: the patch to edit | |
44 """ | |
45 | |
46 def commit(self, message): | |
47 """ | |
48 commit a patch and push it to the master repository | |
49 """ | |
50 call(['hg', 'qrefresh']) | |
51 call(['hg', 'qcommit', '-m', message]) | |
52 root = subprocess.Popen(['hg', 'root'], stdout=subprocess.PIPE).communicate()[0] | |
53 os.chdir(os.path.join(root, '.hg', 'patches')) | |
54 call(['hg', 'push']) | |
55 | |
56 def pull(self, repo=None): | |
57 """ | |
58 pull from the root repository | |
59 """ | |
60 # TODO: commit prior to realignment | |
61 call(['hg', 'qpop', '--all']) | |
62 call(['hg', 'pull'] + repo and [repo] or []) | |
63 call(['hg', 'qpush', '--all']) | |
2
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
64 |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
65 def files(self): |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
66 """ |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
67 list the files added by the top patch |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
68 """ |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
69 # TODO: should only list top-level directories, otherwise it's silly |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
70 _oldcwd = os.getcwd() |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
71 process = subprocess.Popen("hg qdiff | grep '^+++ ' | sed 's/+++ b\///'", stdout=subprocess.PIPE) |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
72 stdout, stderr = process.communicate() |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
73 return stdout |
dedf4c4c2ba2
add a function to list files (incomplete)
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
74 |
0 | 75 |
76 def main(args=sys.argv[1:]): | |
77 parser = CommandParser(HQ) | |
78 options, args = parser.parse_args(args) | |
79 parser.invoke(args) | |
80 | |
81 if __name__ == '__main__': | |
82 main() |