Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
35236:5a62910948d2 | 35237:8df8ce2cc5dd |
---|---|
7 # GNU General Public License version 2 or any later version. | 7 # GNU General Public License version 2 or any later version. |
8 | 8 |
9 from __future__ import absolute_import | 9 from __future__ import absolute_import |
10 | 10 |
11 from .node import hex | 11 from .node import hex |
12 | |
13 from . import ( | |
14 vfs as vfsmod, | |
15 ) | |
16 | |
17 # directory name in .hg/ in which remotenames files will be present | |
18 remotenamedir = 'remotenames' | |
19 | |
20 def writeremotenamefile(repo, remotepath, names, nametype): | |
21 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) | |
22 f = vfs(nametype, 'w', atomictemp=True) | |
23 # write the storage version info on top of file | |
24 # version '0' represents the very initial version of the storage format | |
25 f.write('0\n\n') | |
26 | |
27 for name, node in sorted(names.iteritems()): | |
28 if nametype == "branches": | |
29 for n in node: | |
30 f.write('%s\0%s\0%s\n' % (n, remotepath, name)) | |
31 elif nametype == "bookmarks": | |
32 if node: | |
33 f.write('%s\0%s\0%s\n' % (node, remotepath, name)) | |
34 | |
35 f.close() | |
36 | |
37 def saveremotenames(repo, remotepath, branches=None, bookmarks=None): | |
38 """ | |
39 save remotenames i.e. remotebookmarks and remotebranches in their | |
40 respective files under ".hg/remotenames/" directory. | |
41 """ | |
42 wlock = repo.wlock() | |
43 try: | |
44 if bookmarks: | |
45 writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') | |
46 if branches: | |
47 writeremotenamefile(repo, remotepath, branches, 'branches') | |
48 finally: | |
49 wlock.release() | |
12 | 50 |
13 def pullremotenames(localrepo, remoterepo): | 51 def pullremotenames(localrepo, remoterepo): |
14 """ | 52 """ |
15 pulls bookmarks and branches information of the remote repo during a | 53 pulls bookmarks and branches information of the remote repo during a |
16 pull or clone operation. | 54 pull or clone operation. |
29 bmap[branch] = [] | 67 bmap[branch] = [] |
30 for node in nodes: | 68 for node in nodes: |
31 if node in repo and not repo[node].obsolete(): | 69 if node in repo and not repo[node].obsolete(): |
32 bmap[branch].append(hex(node)) | 70 bmap[branch].append(hex(node)) |
33 | 71 |
34 # writing things to ui till the time we import the saving functionality | 72 saveremotenames(localrepo, remotepath, bmap, bookmarks) |
35 ui = localrepo.ui | |
36 ui.write("\nRemotenames info\npath: %s\n" % remotepath) | |
37 ui.write("Bookmarks:\n") | |
38 for bm, node in bookmarks.iteritems(): | |
39 ui.write("%s: %s\n" % (bm, node)) | |
40 ui.write("Branches:\n") | |
41 for branch, node in bmap.iteritems(): | |
42 ui.write("%s: %s\n" % (branch, node)) | |
43 ui.write("\n") |