Mercurial > hg
annotate mercurial/logexchange.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 876494fd967d |
children | 687b865b95ad |
rev | line source |
---|---|
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
1 # logexchange.py |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
2 # |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2017 Augie Fackler <raf@durin42.com> |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
4 # Copyright 2017 Sean Farley <sean@farley.io> |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
5 # |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
7 # GNU General Public License version 2 or any later version. |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
8 |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
9 from __future__ import absolute_import |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
10 |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
11 from .node import hex |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
12 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
13 from . import ( |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
14 util, |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
15 vfs as vfsmod, |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
16 ) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
17 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
18 # directory name in .hg/ in which remotenames files will be present |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
19 remotenamedir = 'logexchange' |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
20 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
21 |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
22 def readremotenamefile(repo, filename): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
23 """ |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
24 reads a file from .hg/logexchange/ directory and yields it's content |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
25 filename: the file to be read |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
26 yield a tuple (node, remotepath, name) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
27 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
28 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
29 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
30 if not vfs.exists(filename): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
31 return |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
32 f = vfs(filename) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
33 lineno = 0 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
34 for line in f: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
35 line = line.strip() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
36 if not line: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
37 continue |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
38 # contains the version number |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
39 if lineno == 0: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
40 lineno += 1 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
41 try: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
42 node, remote, rname = line.split('\0') |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
43 yield node, remote, rname |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
44 except ValueError: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
45 pass |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
46 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
47 f.close() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
48 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
49 |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
50 def readremotenames(repo): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
51 """ |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
52 read the details about the remotenames stored in .hg/logexchange/ and |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
53 yields a tuple (node, remotepath, name). It does not yields information |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
54 about whether an entry yielded is branch or bookmark. To get that |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
55 information, call the respective functions. |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
56 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
57 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
58 for bmentry in readremotenamefile(repo, 'bookmarks'): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
59 yield bmentry |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
60 for branchentry in readremotenamefile(repo, 'branches'): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
61 yield branchentry |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
62 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
63 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
64 def writeremotenamefile(repo, remotepath, names, nametype): |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
65 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
66 f = vfs(nametype, 'w', atomictemp=True) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
67 # write the storage version info on top of file |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
68 # version '0' represents the very initial version of the storage format |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
69 f.write('0\n\n') |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
70 |
35240
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
71 olddata = set(readremotenamefile(repo, nametype)) |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
72 # re-save the data from a different remote than this one. |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
73 for node, oldpath, rname in sorted(olddata): |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
74 if oldpath != remotepath: |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
75 f.write('%s\0%s\0%s\n' % (node, oldpath, rname)) |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
76 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
77 for name, node in sorted(names.iteritems()): |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
78 if nametype == "branches": |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
79 for n in node: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
80 f.write('%s\0%s\0%s\n' % (n, remotepath, name)) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
81 elif nametype == "bookmarks": |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
82 if node: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
83 f.write('%s\0%s\0%s\n' % (node, remotepath, name)) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
84 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
85 f.close() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
86 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
87 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
88 def saveremotenames(repo, remotepath, branches=None, bookmarks=None): |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
89 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
90 save remotenames i.e. remotebookmarks and remotebranches in their |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
91 respective files under ".hg/logexchange/" directory. |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
92 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
93 wlock = repo.wlock() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
94 try: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
95 if bookmarks: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
96 writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
97 if branches: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
98 writeremotenamefile(repo, remotepath, branches, 'branches') |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
99 finally: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
100 wlock.release() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
101 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
102 |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
103 def activepath(repo, remote): |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
104 """returns remote path""" |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
105 # is the remote a local peer |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
106 local = remote.local() |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
107 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
108 # determine the remote path from the repo, if possible; else just |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
109 # use the string given to us |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
110 rpath = remote |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
111 if local: |
40420
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
112 rpath = util.pconvert(remote._repo.root) |
37365
1ccd75027abb
py3: use bytes instead of str in instance()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36059
diff
changeset
|
113 elif not isinstance(remote, bytes): |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
114 rpath = remote._url |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
115 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
116 # represent the remotepath with user defined path name if exists |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
117 for path, url in repo.ui.configitems('paths'): |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
118 # remove auth info from user defined url |
37981
bbdc1bc56e58
remotenames: check the remotepath with url containing user information too
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37639
diff
changeset
|
119 noauthurl = util.removeauth(url) |
40420
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
120 |
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
121 # Standardize on unix style paths, otherwise some {remotenames} end up |
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
122 # being an absolute path on Windows. |
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
123 url = util.pconvert(bytes(url)) |
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
124 noauthurl = util.pconvert(noauthurl) |
37981
bbdc1bc56e58
remotenames: check the remotepath with url containing user information too
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37639
diff
changeset
|
125 if url == rpath or noauthurl == rpath: |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
126 rpath = path |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
127 break |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
128 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
129 return rpath |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
130 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
131 |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
132 def pullremotenames(localrepo, remoterepo): |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
133 """ |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
134 pulls bookmarks and branches information of the remote repo during a |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
135 pull or clone operation. |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
136 localrepo is our local repository |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
137 remoterepo is the peer instance |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
138 """ |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
139 remotepath = activepath(localrepo, remoterepo) |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
140 |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
141 with remoterepo.commandexecutor() as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
142 bookmarks = e.callcommand( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
143 'listkeys', {'namespace': 'bookmarks',} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
144 ).result() |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
145 |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
146 # on a push, we don't want to keep obsolete heads since |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
147 # they won't show up as heads on the next pull, so we |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
148 # remove them here otherwise we would require the user |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
149 # to issue a pull to refresh the storage |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
150 bmap = {} |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
151 repo = localrepo.unfiltered() |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
152 |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
153 with remoterepo.commandexecutor() as e: |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
154 branchmap = e.callcommand('branchmap', {}).result() |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
155 |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
156 for branch, nodes in branchmap.iteritems(): |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
157 bmap[branch] = [] |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
158 for node in nodes: |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
159 if node in repo and not repo[node].obsolete(): |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
160 bmap[branch].append(hex(node)) |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
161 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
162 saveremotenames(localrepo, remotepath, bmap, bookmarks) |