changeset 15904:7d28d6a67dd3

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.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 17 Jan 2012 02:55:55 +0100
parents 0329d3b12d8e
children 634d49a8b6db
files hgext/rebase.py tests/test-rebase-mq.t
diffstat 2 files changed, 31 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Tue Jan 17 17:48:59 2012 -0600
+++ b/hgext/rebase.py	Tue Jan 17 02:55:55 2012 +0100
@@ -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):
--- a/tests/test-rebase-mq.t	Tue Jan 17 17:48:59 2012 -0600
+++ b/tests/test-rebase-mq.t	Tue Jan 17 02:55:55 2012 +0100
@@ -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