changeset 85:4748bd485ddf

Add a qcrefresh command that updates the current patch with crecord
author Steve Fink <sfink@mozilla.com>
date Thu, 26 May 2011 12:45:33 -0700
parents a3518e68d5e2
children e87d428ad91f
files crecord/__init__.py
diffstat 1 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/crecord/__init__.py
+++ b/crecord/__init__.py
@@ -49,6 +49,31 @@
     dorecord(ui, repo, committomq, *pats, **opts)
 
 
+def qcrefresh(ui, repo, *pats, **opts):
+    '''interactively update the current patch
+
+    See :hg:`help qrefresh` & :hg:`help crecord` for more information and
+    usage.
+    '''
+
+    try:
+        mq = extensions.find('mq')
+    except KeyError:
+        raise util.Abort(_("'mq' extension not loaded"))
+
+    def refreshmq(ui, repo, *pats, **opts):
+        mq.refresh(ui, repo, *pats, **opts)
+
+    # If the record operation (or subsequent refresh), the top applied patch
+    # will be emptied and the working directory will contain all of its
+    # changes.
+    import pdb
+    pdb.set_trace()
+    clearopts = { 'exclude': '*', 'message': '' }
+    mq.refresh(ui, repo, **clearopts)
+    dorecord(ui, repo, refreshmq, *pats, **opts)
+
+
 cmdtable = {
     "crecord":
         (crecord,
@@ -63,10 +88,10 @@
 def extsetup():
     try:
         keyword = extensions.find('keyword')
-        keyword.restricted += ' crecord qcrecord'
+        keyword.restricted += ' crecord qcrecord qcrefresh'
         try:
             keyword.recordextensions += ' crecord'
-            keyword.recordcommands += ' crecord qcrecord'
+            keyword.recordcommands += ' crecord qcrecord qcrefresh'
         except AttributeError:
             pass
     except KeyError:
@@ -82,6 +107,11 @@
         # backwards compatible with pre 301633755dec
         qnew = 'qnew'
 
+    qrefresh = '^qrefresh'
+    if not qrefresh in mq.cmdtable:
+        # backwards compatible?
+        qrefresh = 'qrefresh'
+
     qcmdtable = {
     "qcrecord":
         (qcrecord,
@@ -90,6 +120,14 @@
          [opt for opt in mq.cmdtable[qnew][1] if opt[1] != 'force'],
 
          _('hg qcrecord [OPTION]... PATCH [FILE]...')),
+
+    "qcrefresh":
+        (qcrefresh,
+
+         # sample options as qrefresh
+         mq.cmdtable[qrefresh][1],
+
+         _('hg qcrecord [OPTION]... PATCH [FILE]...')),
     }
 
     cmdtable.update(qcmdtable)