D939: remotenames: add functionality to store remotenames under .hg/hgremotenames/
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Wed Oct 4 21:53:16 UTC 2017
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This patch moves the functionality from remotenames extension to store
remotenames in .hg/remotenames file to core by changing following things:
1. Each type of remotename will be stored in it's own specific file, hence we
are now storing bookmarks in `.hg/remotenames/bookmarks` and branches in
`.hg/remotenames/branches`.
2. Since each type of remotename is stored in specific file, the format of the
data stored is dropped to emit the nametype thing.
The logic to sync with existing remotenames file and saving journals and other
related things will be moved to core in next patches incrementally.
Thanks to Ryan McElroy to suggesting to store each type in their own file which
makes the data format more better and makes the storage extensible.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D939
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
@@ -7,6 +7,16 @@
from __future__ import absolute_import
+from .node import (
+ hex,
+)
+
+from . import (
+ vfs as vfsmod,
+)
+
+remotenamedir = 'remotenames'
+
def splitremotename(remote):
name = ''
if '/' in remote:
@@ -18,6 +28,56 @@
remote += '/' + ref
return remote
+def saveremotebookmarks(repo, vfs, remotepath, bookmarks):
+ """ save remote bookmarks in .hg/remotenames/bookmarks.
+ The format of the data stored will be:
+
+ `node remotepath/bookmarkname`
+
+ bookmarks is a dictionary of remote bookmarks.
+ """
+
+ f = vfs('bookmarks', 'w', atomictemp=True)
+
+ for bookmark, node in bookmarks.iteritems():
+ if node:
+ f.write('%s %s\n' %
+ (node, joinremotename(remotepath, bookmark)))
+ f.close()
+
+def saveremotebranches(repo, vfs, remotepath, branches):
+ """ save remote branches is .hg/remotenames/branches.
+ The format of the data stored will be:
+
+ `node remotepath/branchname`
+
+ branches is a dictionary of remote branches.
+ """
+
+ f = vfs('branches', 'w', atomictemp=True)
+
+ for branch, nodes in branches.iteritems():
+ for n in nodes:
+ rname = joinremotename(remotepath, branch)
+ f.write('%s %s\n' % (hex(n), rname))
+
+ f.close()
+
+def saveremotenames(repo, remotepath, branches=None, bookmarks=None):
+ """ save remotenames i.e. remotebookmarks and remotebranches in their
+ respective files under ".hg/remotenames/" directory.
+ """
+
+ vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
+ wlock = repo.wlock()
+ try:
+ if bookmarks:
+ saveremotebookmarks(repo, vfs, remotepath, bookmarks)
+ if branches:
+ saveremotebranches(repo, vfs, remotepath, branches)
+ finally:
+ wlock.release()
+
def pullremotenames(localrepo, remoterepo, remotepath):
""" pulls bookmarks and branches information of the remote repo during a
pull or clone operation.
@@ -37,3 +97,5 @@
for node in nodes:
if node in repo and not repo[node].obsolete():
bmap[branch].append(node)
+
+ saveremotenames(localrepo, remotepath, bmap, bookmarks)
To: pulkit, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list