[PATCH 5 of 5] hg qrecord -- like record, but for mq

Kirill Smelkov kirr at mns.spb.ru
Thu Dec 27 13:01:45 CST 2007


# HG changeset patch
# User Kirill Smelkov <kirr at mns.spb.ru>
# Date 1198781962 -10800
# Node ID 35183136d09938b00e23143014832b8b160dec47
# Parent  eda06f8a6316b650b557710a69f8d193b75b2e35
hg qrecord -- like record, but for mq

I'm a former Darcs user, and I've discovered that it is very convenient to
actually perform development using MQ first, and only when the patches are
'ready' move them to project's history in stone.


Usually I work on some topic, temporarily forgetting about any version control,
and just do coding, experimenting, debugging, etc.

After some time, I approach a moment, where my work should actually go to
patches/commits, and here is the problem::

    As it is now, there is no way to put part of the changes into one patch,
    and another part of the changes into second patch.

    This works, but only when changes are touching separate files, and for
    semantically different changes touching the same file(s) there is now
    pretty way to put them into separate patches.

For some time, I've tolerated the pain to run vim patches/... and move hunks
between files by hand, but I think this affects my productivity badly.


So, here is the first step towards untiing the problem:

    Let's use 'hg qrecord' for mq, like we use 'hg record' for usual commits!

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -5,10 +5,10 @@
 # This software may be used and distributed according to the terms of
 # the GNU General Public License, incorporated herein by reference.
 
-'''interactive change selection during commit'''
+'''interactive change selection during commit or qrefresh'''
 
 from mercurial.i18n import _
-from mercurial import cmdutil, commands, cmdutil, hg, mdiff, patch, revlog
+from mercurial import cmdutil, commands, cmdutil, extensions, hg, mdiff, patch, revlog
 from mercurial import util
 import copy, cStringIO, errno, operator, os, re, shutil, tempfile
 
@@ -367,6 +367,23 @@ def record(ui, repo, *pats, **opts):
     dorecord(ui, repo, record_commiter, *pats, **opts)
 
 
+def qrecord(ui, repo, *pats, **opts):
+    '''interactively select changes for qrefresh
+
+    see 'hg help record' for more information and usage
+    '''
+
+    try:
+        mq = extensions.find('mq')
+    except KeyError:
+        raise util.Abort(_("'mq' extension not loaded"))
+
+    def qrecord_commiter(ui, repo, pats, opts):
+        mq.refresh(ui, repo, *pats, **opts)
+
+    dorecord(ui, repo, qrecord_commiter, *pats, **opts)
+
+
 def dorecord(ui, repo, committer, *pats, **opts):
     if not ui.interactive:
         raise util.Abort(_('running non-interactively, use commit instead'))
@@ -470,12 +487,41 @@ def dorecord(ui, repo, committer, *pats,
                 pass
     return cmdutil.commit(ui, repo, recordfunc, pats, opts)
 
+
+record_opts = \
+         [
+          ('', 'darcs', None,
+           _('try to mimic "darcs record"')),
+         ]
+
 cmdtable = {
     "record":
         (record,
-         [('A', 'addremove', None,
-           _('mark new/missing files as added/removed before committing')),
-          ('', 'darcs', None, _('try to mimic "darcs record"')),
-         ] + commands.walkopts + commands.commitopts + commands.commitopts2,
+         record_opts + 
+
+         # add commit options
+         commands.table['^commit|ci'][1],
+
          _('hg record [OPTION]... [FILE]...')),
 }
+
+
+def extsetup():
+    try:
+        mq = extensions.find('mq')
+    except KeyError:
+        return
+
+    qcmdtable = {
+    "qrecord":
+        (qrecord,
+         record_opts +
+
+         # add qrefresh options
+         mq.cmdtable['^qrefresh'][1],
+
+         _('hg qrecord [OPTION]... [FILE]...')),
+    }
+
+    cmdtable.update(qcmdtable)
+


More information about the Mercurial-devel mailing list