Patchwork D1357: remotenames: consider existing data while storing newer data

login
register
mail settings
Submitter phabricator
Date Nov. 10, 2017, 7:01 p.m.
Message ID <differential-rev-PHID-DREV-yrgja3fivtpifaa5zzgi-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25467/
State Superseded
Headers show

Comments

phabricator - Nov. 10, 2017, 7:01 p.m.
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




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 13, 2017, 10:32 p.m.
durin42 accepted this revision as: durin42.
durin42 added a comment.


  Seems fine, though this use case does make me wonder (a little) if we should give up and use sqlite for this so we don't end up constantly rewriting a massive file.
  
  Don't rewrite in that direction though unless someone else wants to see that though.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Nov. 29, 2017, 10:06 p.m.
pulkit abandoned this revision.
pulkit added a comment.


  Updated the series with new differentials https://phab.mercurial-scm.org/D1547 to  https://phab.mercurial-scm.org/D1551.

REPOSITORY
  rHG Mercurial

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

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

Patch

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))