D940: remotenames: add functions to read remotenames data from .hg/remotenames/

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Wed Oct 4 21:53:26 UTC 2017


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

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

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

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
@@ -28,6 +28,61 @@
         remote += '/' + ref
     return remote
 
+def readremotenamefile(repo, vfs, 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)
+    """
+
+    f = vfs(filename)
+    for line in f:
+        line = line.strip()
+        if not line:
+            continue
+
+        node, name = line.split()
+        remote, rname = splitremotename(name)
+
+        yield node, remote, rname
+
+def readremotenames(repo):
+    """ 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.
+    """
+
+    vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
+
+    for bmentry in readremotenamefile(repo, vfs, 'bookmarks'):
+        yield bmentry
+
+def readremotebookmarks(repo, remotepath=None):
+    """ read the remotebookmarks stored in .hg/remotenames/bookmarks and yield a
+    tuple of (node, remotepath, name)
+
+    If remotepath is passed, the entries with the same remotepath are yielded
+    only.
+    """
+    vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
+    for bmentry in readremotenamefile(repo, vfs, 'bookmarks'):
+        if bmentry[1] != remotepath:
+            yield bmentry
+
+def readremotebranches(repo, remotepath=None):
+    """ read the remotebranches stored in .hg/remotenames/branches and yield a
+    tuple of (node, remotepath, name)
+
+    If remotepath is passed, the entries with the same remotepath are yielded
+    only.
+    """
+    vfs = vfsmod.vfs(repo.vfs.join(remotenamedir))
+    for bmentry in readremotenamefile(repo, vfs, 'branches'):
+        if bmentry[1] != remotepath:
+            yield bmentry
+
 def saveremotebookmarks(repo, vfs, remotepath, bookmarks):
     """ save remote bookmarks in .hg/remotenames/bookmarks.
     The format of the data stored will be:



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


More information about the Mercurial-devel mailing list