[PATCH] rebase: write series file without removed mq patches

Mads Kiilerich mads at kiilerich.com
Mon Jan 16 19:57:34 CST 2012


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1326765355 -3600
# Node ID 691e818a471349dfa4feabf905d0f53686188fc8
# Parent  476a981fdf341f5bedbd958ca6c8e930fe35b5f9
rebase: write series file without removed mq patches

Rebase will remove empty changesets and will also completely remove the mq
patch file for rebased empty patches.

Starting with b28004513977 (1.9) it would preserve guards by writing the old
series file back. That would however also reintroduce removed patch files in
the series file and the inconsistency would make qpop + qpush fail.

This patch backs out most of b28004513977 and makes sure guards are preserved
without reintroducing removed patches.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -460,9 +460,13 @@
                 mq.qimport(repo, (), patchname=name, git=isgit,
                                 rev=[str(state[rev])])
 
-        # restore old series to preserve guards
-        mq.fullseries = original_series
-        mq.series_dirty = True
+        # restore missing guards
+        for s in original_series:
+            pname = mq.guard_re.split(s, 1)[0]
+            if pname in mq.fullseries:
+                repo.ui.debug('restoring guard for patch %s' % (pname))
+                mq.fullseries[mq.fullseries.index(pname)] = s
+                mq.series_dirty = True
         mq.savedirty()
 
 def updatebookmarks(repo, nstate, originalbookmarks, **opts):
diff --git a/tests/test-rebase-mq.t b/tests/test-rebase-mq.t
--- a/tests/test-rebase-mq.t
+++ b/tests/test-rebase-mq.t
@@ -244,7 +244,7 @@
   $ hg ci -Am a
   adding a
 
-Create mq repo with guarded patches foo and bar:
+Create mq repo with guarded patches foo and bar and empty patch:
 
   $ hg qinit
   $ hg qnew foo
@@ -256,6 +256,8 @@
   popping foo
   patch queue now empty
 
+  $ hg qnew empty-important -m 'important commit message'
+
   $ hg qnew bar
   $ hg qguard bar +baz
   $ echo bar > bar
@@ -263,13 +265,16 @@
   $ hg qref
 
   $ hg qguard -l
+  empty-important: unguarded
   bar: +baz
   foo: +baz
 
   $ hg tglog
-  @  1:* '[mq]: bar' tags: bar qbase qtip tip (glob)
+  @  2: '[mq]: bar' tags: bar qtip tip
   |
-  o  0:* 'a' tags: qparent (glob)
+  o  1: 'important commit message' tags: empty-important qbase
+  |
+  o  0: 'a' tags: qparent
   
 Create new head to rebase bar onto:
 
@@ -279,28 +284,35 @@
   $ hg add b
   $ hg ci -m b
   created new head
-  $ hg up -C 1
+  $ hg up -C 2
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ echo a >> a
   $ hg qref
 
   $ hg tglog
-  @  2:* '[mq]: bar' tags: bar qbase qtip tip (glob)
+  @  3: '[mq]: bar' tags: bar qtip tip
   |
-  | o  1:* 'b' tags: (glob)
+  | o  2: 'b' tags:
+  | |
+  o |  1: 'important commit message' tags: empty-important qbase
   |/
-  o  0:* 'a' tags: qparent (glob)
+  o  0: 'a' tags: qparent
   
 
-Rebase bar (make sure series order is preserved):
+Rebase bar (make sure series order is preserved and empty-important also is
+removed from the series):
 
   $ hg qseries
+  empty-important
+  bar
+  foo
+  $ [ -f .hg/patches/empty-important ]
+  $ hg -q rebase -d 2
+  $ hg qseries
   bar
   foo
-  $ hg -q rebase -d 1
-  $ hg qseries
-  bar
-  foo
+  $ [ -f .hg/patches/empty-important ]
+  [1]
 
   $ hg qguard -l
   bar: +baz


More information about the Mercurial-devel mailing list