[PATCH] strip: move bookmarks to nearest ancestor rather than '.'

Augie Fackler raf at durin42.com
Thu Jun 28 09:04:14 CDT 2012


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1340842377 18000
# Node ID 82673d82425278423744b8b05144fd02db933e4d
# Parent  3dd6da761fff59be7dae61588919e80091d29a39
strip: move bookmarks to nearest ancestor rather than '.'

The current behavior of strip has always struck me as a bug when
stripping a bookmarked revision the ancestor of a bookmarked
revision. This change makes bookmarks move to the tipmost ancestor of
the stripped set rather than the currently-checked-out revision, which
is what I always expected should happen.

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -111,6 +111,13 @@
         saverevs.difference_update(descendants)
     savebases = [cl.node(r) for r in saverevs]
     stripbases = [cl.node(r) for r in tostrip]
+    rset = ' or '.join([str(r) for r in tostrip])
+    newbmtarget = repo.revs('sort(heads(ancestors(%r) - (%r)), -rev)',
+                            rset, rset)
+    if newbmtarget:
+        newbmtarget = newbmtarget[0]
+    else:
+        newbmtarget = '.'
 
     bm = repo._bookmarks
     updatebm = []
@@ -174,7 +181,7 @@
                     ui.warn(_('error removing %s: %s\n') % (undofile, str(e)))
 
         for m in updatebm:
-            bm[m] = repo['.'].node()
+            bm[m] = repo[newbmtarget].node()
         bookmarks.write(repo)
     except: # re-raises
         if backupfile:
@@ -192,4 +199,3 @@
         # Multiple branches involved in strip. Will allow branchcache to become
         # invalid and later on rebuilt from scratch
         repo.destroyed()
-
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -390,3 +390,70 @@
   $ echo "925d80f479bc z" > .hg/bookmarks
   $ hg book
   no bookmarks set
+
+test stripping a non-checked-out but bookmarked revision
+
+  $ hg --config extensions.graphlog= log --graph
+  o  changeset:   4:9ba5f110a0b3
+  |  branch:      test
+  |  tag:         tip
+  |  parent:      2:db815d6d32e6
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     y
+  |
+  | @  changeset:   3:125c9a1d6df6
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     x
+  |
+  o  changeset:   2:db815d6d32e6
+  |  parent:      0:f7b1eb17ad24
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     2
+  |
+  | o  changeset:   1:925d80f479bb
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     1
+  |
+  o  changeset:   0:f7b1eb17ad24
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     0
+  
+  $ hg book should-end-on-two
+  $ hg co --clean 4
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg book four
+  $ hg --config extensions.mq= strip 3
+  saved backup bundle to $TESTTMP/.hg/strip-backup/125c9a1d6df6-backup.hg
+should-end-on-two should end up pointing to revision 2, as that's the
+tipmost surviving ancestor of the stripped revision.
+  $ hg --config extensions.graphlog= log --graph
+  @  changeset:   3:9ba5f110a0b3
+  |  branch:      test
+  |  bookmark:    four
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     y
+  |
+  o  changeset:   2:db815d6d32e6
+  |  bookmark:    should-end-on-two
+  |  parent:      0:f7b1eb17ad24
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     2
+  |
+  | o  changeset:   1:925d80f479bb
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     1
+  |
+  o  changeset:   0:f7b1eb17ad24
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     0
+  


More information about the Mercurial-devel mailing list