D1550: remotenames: add functions to read remotenames data from .hg/remotenames/
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Wed Nov 29 16:58:18 EST 2017
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
This patch functions which can be used to read remotenames data from
.hg/remotenames/. The logic for the function which reads the remotenames file is
taken from the remotenames extension.
Previously reviewed as https://phab.mercurial-scm.org/D940.
diff --git a/mercurial/remotenames.py b/mercurial/remotenames.py
@@ -17,6 +17,47 @@
# directory name in .hg/ in which remotenames files will be present
remotenamedir = 'remotenames'
+def readremotenamefile(repo, filename):
+ reads a file from .hg/remotenames/ directory and yields it's content
+ filename: the file to be read
+ yield a tuple (node, remotepath, name)
+ vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
+ if not vfs.exists(filename):
+ f = vfs(filename)
+ lineno = 0
+ for line in f:
+ line = line.strip()
+ if not line:
+ # contains the version number
+ if lineno == 0:
+ lineno += 1
+ node, remote, rname = line.split('\0')
+ yield node, remote, rname
+ read the details about the remotenames stored in .hg/remotenames/ and
+ yields a tuple (node, remotepath, name). It does not yields information
+ about whether an entry yielded is branch or bookmark. To get that
+ information, call the respective functions.
+ for bmentry in readremotenamefile(repo, 'bookmarks'):
+ yield bmentry
+ for branchentry in readremotenamefile(repo, 'branches'):
+ yield branchentry
def writeremotenamefile(repo, remotepath, names, nametype):
vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
f = vfs(nametype, 'w', atomictemp=True)
To: pulkit, #hg-reviewers
More information about the Mercurial-devel