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

Dan Villiom Podlaski Christiansen danchr at gmail.com
Mon Jul 6 08:23:00 CDT 2009

# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1246880934 -7200
# Node ID fbc1220dbe69eece9b5c293595e3055adf7c6a5a
# Parent  91b8a675b048cc4aabd3ddb898bbe1cc34128c0f
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 @@ applied 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:
 Common tasks (use "hg help command" for more details):
 prepare repository to work with patches   qinit
@@ -38,6 +45,21 @@ import os, sys, re, errno
 commands.norepo += " qclone"
+# list of commands to wrap; only ones which require a repository
+wrappedcmds = set(cmd.lstrip('^').split('|', 1)[0]
+                      for cmd in commands.table.iterkeys())
+wrappedcmds.difference_update(['backout', 'bisect', 'rename', 'root'])
+wrappedcmds = list(sorted(wrappedcmds))
+__doc__ %= {
+    'wrapped':
+        (' ' * 4) + util.wrap(', '.join(cmd for cmd in wrappedcmds
+                                        if not cmd.startswith('debug')), 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
@@ -1721,8 +1743,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."""
+    an unversioned patch repository into a versioned one)."""
     q = repo.mq
     r = q.init(repo, create=opts['create_repo'])
@@ -2493,9 +2514,22 @@ def mqimport(orig, ui, repo, *args, **kw
     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,
+                         _('operate on the patch queue instead')))
 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
 cmdtable = {

More information about the Mercurial-devel mailing list