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: