[PATCH] qrefresh += --amend (#933)

Kirill Smelkov kirr at mns.spb.ru
Fri Jan 18 13:44:12 CST 2008


# HG changeset patch
# User Kirill Smelkov <kirr at mns.spb.ru>
# Date 1200685207 -10800
# Node ID 48fa1430786a31d4e31d80832c4d9215268e25e4
# Parent  fb93c774dffff3601835102fdb57417428307cba
qrefresh += --amend  (#933)

It would be handy to say 'hg qrefresh file.txt' to add changes made to file.txt
to current patch.

Unfortunately this is not qrefresh behaviour -- it just excludes everything but
file.txt from refreshed patch. We discussed this on irc, and it seems people
are against changing this behaviour becuase of backward compatibility.

So here it comes 'hg qrefresh --amend ...' for folks like me who wants just to
incrementally refresh their patches.

----

btw: 'quilt refresh' doesn't allow one to specify files -- they are explicitly
added to a patch with 'quilt add' and 'quilt remove'

btw2: 'stg refresh file' behaves like 'hg qrefresh --amend'

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1025,6 +1025,16 @@
                     match = util.always
                 m, a, r, d, u = repo.status(files=filelist, match=match)[:5]
 
+                # if amending a patch, we always match already-in-patch files
+                if opts.get('amend'):
+                    patchfiles = mm + aa + dd
+                    match_inpatch = dict.fromkeys(patchfiles).__contains__
+                    matchfn_ = matchfn
+                    def matchfn_amend(f):
+                        return matchfn_(f) or match_inpatch(f)
+
+                    matchfn = matchfn_amend
+
                 # we might end up with files that were added between
                 # tip and the dirstate parent, but then changed in the
                 # local dirstate. in this case, we want them to only
@@ -1684,6 +1694,9 @@
     the modifications that match those patterns; the remaining modifications
     will remain in the working directory.
 
+    On the other hand if --amend is specified, changes in specified files will
+    be added to the current patch.
+
     hg add/remove/copy/rename work as usual, though you might want to use
     git-style patches (--git or [diff] git=1) to track copies and renames.
     """
@@ -2276,6 +2289,7 @@
          [('e', 'edit', None, _('edit commit message')),
           ('g', 'git', None, _('use git extended diff format')),
           ('s', 'short', None, _('refresh only files already in the patch')),
+          ('a', 'amend', None, _('append changes from specified files to the patch')),
           ] + commands.walkopts + commands.commitopts + headeropts,
          _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')),
     'qrename|qmv':
diff --git a/tests/test-mq-qrefresh b/tests/test-mq-qrefresh
--- a/tests/test-mq-qrefresh
+++ b/tests/test-mq-qrefresh
@@ -82,3 +82,17 @@
 cat .hg/patches/mqbase | \
 sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
     -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
+
+echo % qrefresh --amend
+hg qrefresh 1/base
+hg qrefresh --amend 2/base
+
+echo % qdiff
+hg qdiff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
+               -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
+
+echo % patch file contents
+cat .hg/patches/mqbase | \
+sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
+    -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
+
diff --git a/tests/test-mq-qrefresh.out b/tests/test-mq-qrefresh.out
--- a/tests/test-mq-qrefresh.out
+++ b/tests/test-mq-qrefresh.out
@@ -159,3 +159,32 @@
 @@ -1,1 +1,1 @@
 -base
 +patched
+% qrefresh --amend
+% qdiff
+diff -r b55ecdccb5cf 1/base
+--- a/1/base
++++ b/1/base
+@@ -1,1 +1,1 @@
+-base
++patched
+diff -r b55ecdccb5cf 2/base
+--- a/2/base
++++ b/2/base
+@@ -1,1 +1,1 @@
+-base
++patched
+% patch file contents
+mqbase
+
+diff -r b55ecdccb5cf 1/base
+--- a/1/base
++++ b/1/base
+@@ -1,1 +1,1 @@
+-base
++patched
+diff -r b55ecdccb5cf 2/base
+--- a/2/base
++++ b/2/base
+@@ -1,1 +1,1 @@
+-base
++patched


More information about the Mercurial-devel mailing list