##// END OF EJS Templates
remotenames: add functionality to store remotenames under .hg/hgremotenames/...
Pulkit Goyal -
r35237:8df8ce2c default
parent child Browse files
Show More
@@ -1,43 +1,72
1 1 # remotenames.py
2 2 #
3 3 # Copyright 2017 Augie Fackler <raf@durin42.com>
4 4 # Copyright 2017 Sean Farley <sean@farley.io>
5 5 #
6 6 # This software may be used and distributed according to the terms of the
7 7 # GNU General Public License version 2 or any later version.
8 8
9 9 from __future__ import absolute_import
10 10
11 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 51 def pullremotenames(localrepo, remoterepo):
14 52 """
15 53 pulls bookmarks and branches information of the remote repo during a
16 54 pull or clone operation.
17 55 localrepo is our local repository
18 56 remoterepo is the peer instance
19 57 """
20 58 remotepath = remoterepo.url()
21 59 bookmarks = remoterepo.listkeys('bookmarks')
22 60 # on a push, we don't want to keep obsolete heads since
23 61 # they won't show up as heads on the next pull, so we
24 62 # remove them here otherwise we would require the user
25 63 # to issue a pull to refresh the storage
26 64 bmap = {}
27 65 repo = localrepo.unfiltered()
28 66 for branch, nodes in remoterepo.branchmap().iteritems():
29 67 bmap[branch] = []
30 68 for node in nodes:
31 69 if node in repo and not repo[node].obsolete():
32 70 bmap[branch].append(hex(node))
33 71
34 # writing things to ui till the time we import the saving functionality
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")
72 saveremotenames(localrepo, remotepath, bmap, bookmarks)
@@ -1,73 +1,75
1 1 Testing the functionality to pull remotenames
2 2 =============================================
3 3
4 4 $ cat >> $HGRCPATH << EOF
5 5 > [alias]
6 6 > glog = log -G -T '{rev}:{node|short} {desc}'
7 7 > EOF
8 8
9 9 Making a server repo
10 10 --------------------
11 11
12 12 $ hg init server
13 13 $ cd server
14 14 $ for ch in {a..h}; do echo "foo" >> $ch; hg ci -Aqm "Added "$ch; done
15 15 $ hg glog
16 16 @ 7:ec2426147f0e Added h
17 17 |
18 18 o 6:87d6d6676308 Added g
19 19 |
20 20 o 5:825660c69f0c Added f
21 21 |
22 22 o 4:aa98ab95a928 Added e
23 23 |
24 24 o 3:62615734edd5 Added d
25 25 |
26 26 o 2:28ad74487de9 Added c
27 27 |
28 28 o 1:29becc82797a Added b
29 29 |
30 30 o 0:18d04c59bb5d Added a
31 31
32 32 $ hg bookmark -r 3 foo
33 33 $ hg bookmark -r 6 bar
34 34 $ hg up 4
35 35 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
36 36 $ hg branch wat
37 37 marked working directory as branch wat
38 38 (branches are permanent and global, did you want a bookmark?)
39 39 $ echo foo >> bar
40 40 $ hg ci -Aqm "added bar"
41 41
42 42 Making a client repo
43 43 --------------------
44 44
45 45 $ cd ..
46 46 $ hg init client
47 47 $ cd client
48 48 $ cat >> .hg/hgrc << EOF
49 49 > [experimental]
50 50 > remotenames = True
51 51 > EOF
52 52
53 53 $ hg pull ../server/
54 54 pulling from ../server/
55 55 requesting all changes
56 56 adding changesets
57 57 adding manifests
58 58 adding file changes
59 59 added 9 changesets with 9 changes to 9 files (+1 heads)
60 60 adding remote bookmark bar
61 61 adding remote bookmark foo
62 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
65 path: file:$TESTTMP/server
66 Bookmarks:
67 foo: 62615734edd52f06b6fb9c2beb429e4fe30d57b8
68 bar: 87d6d66763085b629e6d7ed56778c79827273022
69 Branches:
70 wat: ['3e1487808078543b0af6d10dadf5d46943578db0']
71 default: ['ec2426147f0e39dbc9cef599b066be6035ce691d']
68 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc)
69 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc)
70
71 $ cat .hg/remotenames/branches
72 0
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