D1357: remotenames: consider existing data while storing newer data

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Nov 10 14:01:30 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/D1357

AFFECTED FILES
  mercurial/remotenames.py
  tests/test-remotenames.t

CHANGE DETAILS

diff --git a/tests/test-remotenames.t b/tests/test-remotenames.t
--- a/tests/test-remotenames.t
+++ b/tests/test-remotenames.t
@@ -93,8 +93,12 @@
   searching for changes
   no changes found
   $ cat .hg/remotenames/bookmarks
+  62615734edd52f06b6fb9c2beb429e4fe30d57b8 file:$TESTTMP/server foo
+  87d6d66763085b629e6d7ed56778c79827273022 file:$TESTTMP/server bar
   87d6d66763085b629e6d7ed56778c79827273022 file:$TESTTMP/server2 bar
   62615734edd52f06b6fb9c2beb429e4fe30d57b8 file:$TESTTMP/server2 foo
   $ cat .hg/remotenames/branches
+  3e1487808078543b0af6d10dadf5d46943578db0 file:$TESTTMP/server wat
+  ec2426147f0e39dbc9cef599b066be6035ce691d file:$TESTTMP/server default
   ec2426147f0e39dbc9cef599b066be6035ce691d file:$TESTTMP/server2 default
   3e1487808078543b0af6d10dadf5d46943578db0 file:$TESTTMP/server2 wat
diff --git a/mercurial/remotenames.py b/mercurial/remotenames.py
--- a/mercurial/remotenames.py
+++ b/mercurial/remotenames.py
@@ -60,9 +60,16 @@
 
     bookmarks is a dictionary of remote bookmarks.
     """
+    olddata = set(readremotenamefile(repo, 'bookmarks'))
+
     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))
+
     for bookmark, node in sorted(bookmarks.iteritems()):
         if node:
             f.write('%s %s %s\n' % (node, remotepath, bookmark))
@@ -77,9 +84,16 @@
 
     branches is a dictionary of remote branches.
     """
+    olddata = set(readremotenamefile(repo, 'branches'))
+
     vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
     f = vfs('branches', '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))
+
     for branch, nodes in sorted(branches.iteritems()):
         for n in nodes:
             f.write('%s %s %s\n' % (n, remotepath, branch))



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


More information about the Mercurial-devel mailing list