[PATCH] mq: add -Q/--queue option to some commands for operating on the queue repo

Dan Villiom Podlaski Christiansen danchr at gmail.com
Fri Jul 10 07:57:05 CDT 2009


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1247226340 -7200
# Node ID e7190982f31d44aa90b435851c1b14ee05e7d237
# Parent  52d90da7c7a8f6b5af6ece6b62fb842269983a3e
mq: add -Q/--queue option to some commands for operating on the queue repo.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -14,6 +14,13 @@ patches (subset of known patches).
 Known patches are represented as patch files in the .hg/patches directory.
 Applied patches are both patch files and changesets.
 
+A versioned repository for the patch queue can be created by using the
+-c/--create-repo option for 'qinit', or by using the 'qclone'
+command. To work with this repository, the -Q/--queue option can be
+used with any of the following commands:
+
+%(wrapped)s
+
 Common tasks (use "hg help command" for more details):
 
 prepare repository to work with patches   qinit
@@ -38,6 +45,26 @@ import os, sys, re, errno
 
 commands.norepo += " qclone"
 
+# TODO: replace 'qimport' and 'qclone' with 'import' and 'clone' wrappers.
+
+# list of commands to wrap:
+#   builtin commands that require a repository and aren't either debug
+#   commands, file management commands, or otherwise unsuitable for queues.
+wrappedcmds = ('annotate', 'archive', 'backout',
+               'branch', 'branches', 'cat', 'commit',
+               'diff', 'grep', 'heads', 'incoming',
+               'locate', 'log', 'manifest', 'merge',
+               'outgoing', 'parents', 'pull', 'push',
+               'recover', 'resolve', 'revert', 'rollback', 'root',
+               'status', 'tag', 'tags', 'tip',
+               'update', 'verify')
+# unique & sort
+wrappedcmds = tuple(sorted(set(wrappedcmds)))
+
+__doc__ %= {
+    'wrapped': (' ' * 4) + util.wrap(', '.join(wrappedcmds), 4, 76)
+    }
+
 # Patch names looks like unix-file names.
 # They must be joinable with queue directory and result in the patch path.
 normname = util.normpath
@@ -1720,8 +1747,7 @@ def init(ui, repo, **opts):
     The queue repository is unversioned by default. If -c/--create-repo is
     specified, qinit will create a separate nested repository for patches
     (qinit -c may also be run later to convert an unversioned patch repository
-    into a versioned one). You can use qcommit to commit changes to this queue
-    repository.
+    into a versioned one).
     """
     q = repo.mq
     r = q.init(repo, create=opts['create_repo'])
@@ -1805,7 +1831,7 @@ def clone(ui, source, dest=None, **opts)
             hg.update(dr, dr.changelog.tip())
 
 def commit(ui, repo, *pats, **opts):
-    """commit changes in the queue repository"""
+    """commit changes in the queue repository (DEPRECATED)"""
     q = repo.mq
     r = q.qrepo()
     if not r: raise util.Abort('no queue repository')
@@ -2481,9 +2507,23 @@ def mqimport(orig, ui, repo, *args, **kw
                                    kwargs.get('force'))
     return orig(ui, repo, *args, **kwargs)
 
+def mqwrapper(orig, ui, repo, *args, **kwargs):
+    if kwargs.pop('queue', False):
+        repo = repo.mq.qrepo()
+        if not repo:
+            raise util.Abort(_('versioned patch repository not found'
+                               ' (see qinit -c)'))
+    return orig(ui, repo, *args, **kwargs)
+
 def uisetup(ui):
     extensions.wrapcommand(commands.table, 'import', mqimport)
 
+    for cmd in sorted(wrappedcmds):
+        entry = extensions.wrapcommand(commands.table, cmd, mqwrapper)
+        entry[1].append(('Q', 'queue', None,
+                         _('apply this command to the patch queue repository '
+                           'instead')))
+
 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
 
 cmdtable = {


More information about the Mercurial-devel mailing list