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

login
register
mail settings
Submitter phabricator
Date Nov. 10, 2017, 7:01 p.m.
Message ID <a532e18bd76073cbbdaec0bab3e73fda@localhost.localdomain>
Download mbox | patch
Permalink /patch/25466/
State Not Applicable
Headers show

Comments

phabricator - Nov. 10, 2017, 7:01 p.m.
pulkit updated this revision to Diff 3395.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D940?vs=2437&id=3395

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

AFFECTED FILES
  mercurial/remotenames.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/remotenames.py b/mercurial/remotenames.py
--- a/mercurial/remotenames.py
+++ b/mercurial/remotenames.py
@@ -17,6 +17,40 @@ 
 # 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):
+        return
+    f = vfs(filename)
+    for line in f:
+        line = line.strip()
+        if not line:
+            continue
+
+        node, remote, rname = line.split()
+        yield node, remote, rname
+
+    f.close()
+
+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.
+    """
+
+    for bmentry in readremotenamefile(repo, 'bookmarks'):
+        yield bmentry
+    for branchentry in readremotenamefile(repo, 'branches'):
+        yield branchentry
+
 def saveremotebookmarks(repo, remotepath, bookmarks):
     """
     save remote bookmarks in .hg/remotenames/bookmarks.