D1358: remotenames: store journal entry for bookmarks if journal is loaded

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Nov 10 14:01:37 EST 2017


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1358

AFFECTED FILES
  mercurial/remotenames.py

CHANGE DETAILS

diff --git a/mercurial/remotenames.py b/mercurial/remotenames.py
--- a/mercurial/remotenames.py
+++ b/mercurial/remotenames.py
@@ -8,12 +8,18 @@
 
 from __future__ import absolute_import
 
-from .node import hex
+from .node import (
+    bin,
+    hex,
+)
 
 from . import (
+    util,
     vfs as vfsmod,
 )
 
+# namespace to use when recording an hg journal entry
+journalremotebookmarktype = 'remotebookmark'
 # directory name in .hg/ in which remotenames files will be present
 remotenamedir = 'remotenames'
 
@@ -61,14 +67,26 @@
     bookmarks is a dictionary of remote bookmarks.
     """
     olddata = set(readremotenamefile(repo, 'bookmarks'))
+    oldbooks = {}
 
     vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
     f = vfs('bookmarks', 'w', atomictemp=True)
 
     # re-save the data from a different remote than this one.
     for node, oldpath, rname in sorted(olddata):
         if oldpath != remotepath:
             f.write('%s %s %s\n' % (node, oldpath, rname))
+        else:
+            oldbooks[rname] = node
+
+    # record a journal entry if journal is loaded
+    if util.safehasattr(repo, 'journal'):
+        for bname, newnode in bookmarks.iteritems():
+            oldnode = oldbooks.get(bname, hex(nullid))
+            if oldnode != newnode:
+                joinedremotename = remotepath + '/' + bname
+                repo.journal.record(journalremotebookmarktype, joinedremotename,
+                                    bin(oldnode), bin(newnode))
 
     for bookmark, node in sorted(bookmarks.iteritems()):
         if node:



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list