Mercurial > hg > hq
changeset 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 |
files | hq/main.py |
diffstat | 1 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/hq/main.py Tue May 25 13:39:19 2010 -0700 +++ b/hq/main.py Tue May 25 19:02:21 2010 -0700 @@ -39,11 +39,14 @@ os.chdir(directory) call(['hg', 'qinit', '-c']) if queue: - _oldcwd = os.getcwd() - os.chdir(os.path.join('.hg', 'patches')) - call(['hg', 'pull', '--update', queue]) - os.chdir(_oldcwd) + # pull from the given repository + self._patch_command(*['hg', 'pull', '--update', queue]) + else: + # (optionally) setup a new repo + pass # TODO + if patch: + # create a new patch call(['hg', 'qnew', patch]) def edit(self, patch=None): @@ -58,9 +61,7 @@ """ call(['hg', 'qrefresh']) call(['hg', 'qcommit', '-m', message]) - root = subprocess.Popen(['hg', 'root'], stdout=subprocess.PIPE).communicate()[0] - os.chdir(os.path.join(root, '.hg', 'patches')) - call(['hg', 'push']) + self._patch_command(*['hg', 'push']) def pull(self, repo=None): """ @@ -92,6 +93,17 @@ stdout, stderr = process.communicate() return stdout + def _patch_repo(self): + """the location of the patch repository""" + root = subprocess.Popen(['hg', 'root'], stdout=subprocess.PIPE).communicate()[0] + return os.path.join(root, '.hg', 'patches') + + def _patch_command(self, *command): + """perform a command in the patch repository""" + _oldpwd = os.getcwd() + os.chdir(self._patch_repo()) + call(command) + os.chdir(_oldpwd) def main(args=sys.argv[1:]): parser = CommandParser(HQ)