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") |
|