##// END OF EJS Templates
remotenames: add functionality to store remotenames under .hg/hgremotenames/...
Pulkit Goyal -
r35237:8df8ce2c default
parent child Browse files
Show More
@@ -10,6 +10,44 b' from __future__ import absolute_import'
10
10
11 from .node import hex
11 from .node import hex
12
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()
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
@@ -31,13 +69,4 b' def pullremotenames(localrepo, remoterep'
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")
@@ -60,14 +60,16 b' Making a client repo'
60 adding remote bookmark bar
60 adding remote bookmark bar
61 adding remote bookmark foo
61 adding remote bookmark foo
62 new changesets 18d04c59bb5d:3e1487808078
62 new changesets 18d04c59bb5d:3e1487808078
63 (run 'hg heads' to see heads)
64
65 $ cat .hg/remotenames/bookmarks
66 0
63
67
64 Remotenames info
68 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc)
65 path: file:$TESTTMP/server
69 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc)
66 Bookmarks:
70
67 foo: 62615734edd52f06b6fb9c2beb429e4fe30d57b8
71 $ cat .hg/remotenames/branches
68 bar: 87d6d66763085b629e6d7ed56778c79827273022
72 0
69 Branches:
70 wat: ['3e1487808078543b0af6d10dadf5d46943578db0']
71 default: ['ec2426147f0e39dbc9cef599b066be6035ce691d']
72
73
73 (run 'hg heads' to see heads)
74 ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc)
75 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc)
General Comments 0
You need to be logged in to leave comments. Login now