Patchwork [08,of,10] bookmark: track bookmark changes at the transaction level

login
register
mail settings
Submitter Boris Feld
Date July 15, 2017, 11:42 a.m.
Message ID <a041b7fd158ab0a5dda7.1500118976@FB>
Download mbox | patch
Permalink /patch/22401/
State Accepted
Headers show

Comments

Boris Feld - July 15, 2017, 11:42 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499711213 -7200
#      Mon Jul 10 20:26:53 2017 +0200
# Node ID a041b7fd158ab0a5dda7ef970aa0a238103e896b
# Parent  94da61e581672f5c9616f1ad1336cfaadbdc96a9
# EXP-Topic tr.changes.bookmarks
bookmark: track bookmark changes at the transaction level

The transaction has now a 'bookmarks' dictionary in tr.changes. The structure
of the dictionary is {BOOKMARK_NAME: (OLD_NODE, NEW_NODE)}. If a bookmark is
deleted NEW_NODE will be None. If a bookmark is created OLD_NODE will be None.

If the bookmark is updated multiple time, the initial value is preserved.

Patch

diff -r 94da61e58167 -r a041b7fd158a mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Mon Jul 10 20:10:03 2017 +0200
+++ b/mercurial/bookmarks.py	Mon Jul 10 20:26:53 2017 +0200
@@ -112,11 +112,19 @@ 
     def applychanges(self, repo, tr, changes):
         """Apply a list of changes to bookmarks
         """
+        bmchanges = tr.changes.get('bookmarks')
         for name, node in changes:
+            old = self.get(name)
             if node is None:
                 del self[name]
             else:
                 self[name] = node
+            if bmchanges is not None:
+                # if a previous value exist preserve the "initial" value
+                previous = bmchanges.get(name)
+                if previous is not None:
+                    old = previous[0]
+                bmchanges[name] = (old, node)
         self._recordchange(tr)
 
     def recordchange(self, tr):
diff -r 94da61e58167 -r a041b7fd158a mercurial/localrepo.py
--- a/mercurial/localrepo.py	Mon Jul 10 20:10:03 2017 +0200
+++ b/mercurial/localrepo.py	Mon Jul 10 20:26:53 2017 +0200
@@ -1217,6 +1217,7 @@ 
         tr.changes['revs'] = set()
         tr.changes['obsmarkers'] = set()
         tr.changes['phases'] = {}
+        tr.changes['bookmarks'] = {}
 
         tr.hookargs['txnid'] = txnid
         # note: writing the fncache only during finalize mean that the file is