comparison hq/main.py @ 4:44ea39c3e98f

add methods for dealing with the patch repositories
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 25 May 2010 19:02:21 -0700
parents 8bc27dbf0214
children 448c248b3738
comparison
equal deleted inserted replaced
3:8bc27dbf0214 4:44ea39c3e98f
37 directory = repo.rsplit('/', 1) 37 directory = repo.rsplit('/', 1)
38 call(['hg', 'clone', repo, directory]) 38 call(['hg', 'clone', repo, directory])
39 os.chdir(directory) 39 os.chdir(directory)
40 call(['hg', 'qinit', '-c']) 40 call(['hg', 'qinit', '-c'])
41 if queue: 41 if queue:
42 _oldcwd = os.getcwd() 42 # pull from the given repository
43 os.chdir(os.path.join('.hg', 'patches')) 43 self._patch_command(*['hg', 'pull', '--update', queue])
44 call(['hg', 'pull', '--update', queue]) 44 else:
45 os.chdir(_oldcwd) 45 # (optionally) setup a new repo
46 pass # TODO
47
46 if patch: 48 if patch:
49 # create a new patch
47 call(['hg', 'qnew', patch]) 50 call(['hg', 'qnew', patch])
48 51
49 def edit(self, patch=None): 52 def edit(self, patch=None):
50 """ 53 """
51 edit a patch 54 edit a patch
56 """ 59 """
57 commit a patch and push it to the master repository 60 commit a patch and push it to the master repository
58 """ 61 """
59 call(['hg', 'qrefresh']) 62 call(['hg', 'qrefresh'])
60 call(['hg', 'qcommit', '-m', message]) 63 call(['hg', 'qcommit', '-m', message])
61 root = subprocess.Popen(['hg', 'root'], stdout=subprocess.PIPE).communicate()[0] 64 self._patch_command(*['hg', 'push'])
62 os.chdir(os.path.join(root, '.hg', 'patches'))
63 call(['hg', 'push'])
64 65
65 def pull(self, repo=None): 66 def pull(self, repo=None):
66 """ 67 """
67 pull from the root repository 68 pull from the root repository
68 """ 69 """
90 _oldcwd = os.getcwd() 91 _oldcwd = os.getcwd()
91 process = subprocess.Popen("hg qdiff | grep '^+++ ' | sed 's/+++ b\///'", stdout=subprocess.PIPE) 92 process = subprocess.Popen("hg qdiff | grep '^+++ ' | sed 's/+++ b\///'", stdout=subprocess.PIPE)
92 stdout, stderr = process.communicate() 93 stdout, stderr = process.communicate()
93 return stdout 94 return stdout
94 95
96 def _patch_repo(self):
97 """the location of the patch repository"""
98 root = subprocess.Popen(['hg', 'root'], stdout=subprocess.PIPE).communicate()[0]
99 return os.path.join(root, '.hg', 'patches')
100
101 def _patch_command(self, *command):
102 """perform a command in the patch repository"""
103 _oldpwd = os.getcwd()
104 os.chdir(self._patch_repo())
105 call(command)
106 os.chdir(_oldpwd)
95 107
96 def main(args=sys.argv[1:]): 108 def main(args=sys.argv[1:]):
97 parser = CommandParser(HQ) 109 parser = CommandParser(HQ)
98 options, args = parser.parse_args(args) 110 options, args = parser.parse_args(args)
99 parser.invoke(args) 111 parser.invoke(args)