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
|
|
29
|
|
30 def clone(self, repo, patch=None):
|
|
31 """clone the repository and begin a patch queue"""
|
|
32 directory = repo.rsplit('/', 1)
|
|
33 call(['hg', 'clone', repo, directory])
|
|
34 os.chdir(directory)
|
|
35 call(['hg', 'qinit', '-c'])
|
|
36 if patch:
|
|
37 call(['hg', 'qnew', patch])
|
|
38
|
|
39 def edit(self, patch=None):
|
|
40 """
|
|
41 edit a patch
|
|
42 - patch: the patch to edit
|
|
43 """
|
|
44
|
|
45 def commit(self, message):
|
|
46 """
|
|
47 commit a patch and push it to the master repository
|
|
48 """
|
|
49 call(['hg', 'qrefresh'])
|
|
50 call(['hg', 'qcommit', '-m', message])
|
|
51 root = subprocess.Popen(['hg', 'root'], stdout=subprocess.PIPE).communicate()[0]
|
|
52 os.chdir(os.path.join(root, '.hg', 'patches'))
|
|
53 call(['hg', 'push'])
|
|
54
|
|
55 def pull(self, repo=None):
|
|
56 """
|
|
57 pull from the root repository
|
|
58 """
|
|
59 # TODO: commit prior to realignment
|
|
60 call(['hg', 'qpop', '--all'])
|
|
61 call(['hg', 'pull'] + repo and [repo] or [])
|
|
62 call(['hg', 'qpush', '--all'])
|
|
63
|
|
64
|
|
65 def main(args=sys.argv[1:]):
|
|
66 parser = CommandParser(HQ)
|
|
67 options, args = parser.parse_args(args)
|
|
68 parser.invoke(args)
|
|
69
|
|
70 if __name__ == '__main__':
|
|
71 main()
|