[PATCH 2 of 7] histedit: move topmost bookmark movement to a separate function

Jun Wu quark at fb.com
Sat Jul 8 19:51:30 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1499557645 25200
#      Sat Jul 08 16:47:25 2017 -0700
# Node ID b81424281f4ae58803a20c607c83359948b4fb61
# Parent  13b585039b6ee38f06fa2974f780e0187b113604
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r b81424281f4a
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.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1542,4 +1542,20 @@ def processreplacement(state):
     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"""
@@ -1547,14 +1563,7 @@ def movebookmarks(ui, repo, mapping, old
         # 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)


More information about the Mercurial-devel mailing list