Patchwork [01,of,12] bookmark: introduce a 'applychanges' function to gather bookmark movement

login
register
mail settings
Submitter Boris Feld
Date July 14, 2017, 5:53 p.m.
Message ID <e94441a7d9e334c5b9e6.1500054839@FB>
Download mbox | patch
Permalink /patch/22362/
State Accepted
Headers show

Comments

Boris Feld - July 14, 2017, 5:53 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499698894 -7200
#      Mon Jul 10 17:01:34 2017 +0200
# Node ID e94441a7d9e334c5b9e604b9f6cabe4182cd5550
# Parent  7c33adc823e008019f0f06ff5f357ca628f3ab34
# EXP-Topic tr.changes.bookmarks
bookmark: introduce a 'applychanges' function to gather bookmark movement

We want to track bookmark movement within a transaction. For this we need a
more centralized way to update bookmarks.

For this purpose we introduce a new 'applychanges' method that apply a list of
changes encoded as '(name, node)'. We'll cover all bookmark updating code to
this new method in later changesets and add bookmark move in the transaction
when all will be migrated.

Patch

diff -r 7c33adc823e0 -r e94441a7d9e3 mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Thu Mar 30 00:33:00 2017 -0400
+++ b/mercurial/bookmarks.py	Mon Jul 10 17:01:34 2017 +0200
@@ -109,6 +109,16 @@ 
         self._clean = False
         return dict.__delitem__(self, key)
 
+    def applychanges(self, repo, tr, changes):
+        """Apply a list of changes to bookmarks
+        """
+        for name, node in changes:
+            if node is None:
+                del self[name]
+            else:
+                self[name] = node
+        self.recordchange(tr)
+
     def recordchange(self, tr):
         """record that bookmarks have been changed in a transaction