Mercurial > hg
diff mercurial/remotenames.py @ 35237:8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
This patch moves the functionality from remotenames extension to store
remotenames to core.
Storage format used by remotenames extension:
A single file `.hg/remotenames` with an entry in each line where each line is of
format:
`node nametype remotepath/name`
where nametype is either 'bookmarks' or 'branches'.
This was not the best way to store data, so while moving to core the storage
format was changed but yet not the final format. The storage format used by core
after this patch will be:
* A file for each type of name i.e. bookmarks and branches in .hg/remotenames/
directory
* A version number on the top of the file. The version for current format is 0.
* An entry in each line where each line is of the format
`node\0remotepath\0name`
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, Augie and Durham for suggestions on storage format.
Previously reviewed as D939.
Differential Revision: https://phab.mercurial-scm.org/D1548
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 05 Oct 2017 00:44:38 +0530 |
parents | 5a62910948d2 |
children | 744d1c874a59 |
line wrap: on
line diff
--- a/mercurial/remotenames.py Thu Oct 05 00:02:02 2017 +0530 +++ b/mercurial/remotenames.py Thu Oct 05 00:44:38 2017 +0530 @@ -10,6 +10,44 @@ from .node import hex +from . import ( + vfs as vfsmod, +) + +# directory name in .hg/ in which remotenames files will be present +remotenamedir = 'remotenames' + +def writeremotenamefile(repo, remotepath, names, nametype): + vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) + f = vfs(nametype, 'w', atomictemp=True) + # write the storage version info on top of file + # version '0' represents the very initial version of the storage format + f.write('0\n\n') + + for name, node in sorted(names.iteritems()): + if nametype == "branches": + for n in node: + f.write('%s\0%s\0%s\n' % (n, remotepath, name)) + elif nametype == "bookmarks": + if node: + f.write('%s\0%s\0%s\n' % (node, remotepath, name)) + + 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. + """ + wlock = repo.wlock() + try: + if bookmarks: + writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') + if branches: + writeremotenamefile(repo, remotepath, branches, 'branches') + finally: + wlock.release() + def pullremotenames(localrepo, remoterepo): """ pulls bookmarks and branches information of the remote repo during a @@ -31,13 +69,4 @@ if node in repo and not repo[node].obsolete(): bmap[branch].append(hex(node)) - # writing things to ui till the time we import the saving functionality - ui = localrepo.ui - ui.write("\nRemotenames info\npath: %s\n" % remotepath) - ui.write("Bookmarks:\n") - for bm, node in bookmarks.iteritems(): - ui.write("%s: %s\n" % (bm, node)) - ui.write("Branches:\n") - for branch, node in bmap.iteritems(): - ui.write("%s: %s\n" % (branch, node)) - ui.write("\n") + saveremotenames(localrepo, remotepath, bmap, bookmarks)