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