changeset 33346:7aa5160bdbf5

histedit: move topmost bookmark movement to a separate function histedit treats topmost bookmark movement specially. The rest of the bookmark movement could be handled by scmutil.cleanupnodes. So let's move the special logic out to make the patch easier to review.
author Jun Wu <quark@fb.com>
date Sat, 08 Jul 2017 16:47:25 -0700
parents 4192694b4844
children dc318f93bd77
files hgext/histedit.py
diffstat 1 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Sat Jul 08 16:04:21 2017 -0700
+++ b/hgext/histedit.py	Sat Jul 08 16:47:25 2017 -0700
@@ -1541,21 +1541,30 @@
 
     return final, tmpnodes, new, newtopmost
 
+def movetopmostbookmarks(repo, oldtopmost, newtopmost):
+    """Move bookmark from oldtopmost to newly created topmost
+
+    This is arguably a feature and we may only want that for the active
+    bookmark. But the behavior is kept compatible with the old version for now.
+    """
+    if not oldtopmost or not newtopmost:
+        return
+    oldbmarks = repo.nodebookmarks(oldtopmost)
+    if oldbmarks:
+        with repo.lock(), repo.transaction('histedit') as tr:
+            marks = repo._bookmarks
+            for name in oldbmarks:
+                marks[name] = newtopmost
+            marks.recordchange(tr)
+
 def movebookmarks(ui, repo, mapping, oldtopmost, newtopmost):
     """Move bookmark from old to newly created node"""
     if not mapping:
         # if nothing got rewritten there is not purpose for this function
         return
+    movetopmostbookmarks(repo, oldtopmost, newtopmost)
     moves = []
     for bk, old in sorted(repo._bookmarks.iteritems()):
-        if old == oldtopmost:
-            # special case ensure bookmark stay on tip.
-            #
-            # This is arguably a feature and we may only want that for the
-            # active bookmark. But the behavior is kept compatible with the old
-            # version for now.
-            moves.append((bk, newtopmost))
-            continue
         base = old
         new = mapping.get(base, None)
         if new is None: