Mercurial > hg
annotate mercurial/logexchange.py @ 50738:2eaa883778f7 stable
heptapod-ci: (hopefully) fix the pipeline savings system
There is no easy way for me to test this outside of the actual repo since
it would require setting up `heptapod-runner` locally, making a Git repo
with the right changes, etc. It's not worth my time at this point.
If this fails, I'll try to ask for help from Georges, the maintainer
of Heptapod.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 03 Jul 2023 15:28:17 +0200 |
parents | 5bceea1a8234 |
children | f4733654f144 |
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 |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
10 from .node import hex |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
11 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
12 from . import ( |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
13 util, |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
14 vfs as vfsmod, |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
15 ) |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
16 from .utils import ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
17 urlutil, |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
18 ) |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
19 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
20 # directory name in .hg/ in which remotenames files will be present |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
21 remotenamedir = b'logexchange' |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
22 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
23 |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
24 def readremotenamefile(repo, filename): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
25 """ |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
30 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
31 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
|
32 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
|
33 return |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
34 f = vfs(filename) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
35 lineno = 0 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
36 for line in f: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
37 line = line.strip() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
38 if not line: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
39 continue |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
40 # contains the version number |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
41 if lineno == 0: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
42 lineno += 1 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
43 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
44 node, remote, rname = line.split(b'\0') |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
45 yield node, remote, rname |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
46 except ValueError: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
47 pass |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
48 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
49 f.close() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
50 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
51 |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
52 def readremotenames(repo): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
53 """ |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
59 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 for bmentry in readremotenamefile(repo, b'bookmarks'): |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
61 yield bmentry |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 for branchentry in readremotenamefile(repo, b'branches'): |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
63 yield branchentry |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
64 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
65 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
66 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
|
67 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
68 f = vfs(nametype, b'w', atomictemp=True) |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
69 # 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
|
70 # version '0' represents the very initial version of the storage format |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
71 f.write(b'0\n\n') |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
72 |
35240
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
73 olddata = set(readremotenamefile(repo, nametype)) |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
74 # 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
|
75 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
|
76 if oldpath != remotepath: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
77 f.write(b'%s\0%s\0%s\n' % (node, oldpath, rname)) |
35240
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
78 |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
79 for name, node in sorted(names.items()): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
80 if nametype == b"branches": |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
81 for n in node: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 f.write(b'%s\0%s\0%s\n' % (n, remotepath, name)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
83 elif nametype == b"bookmarks": |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
84 if node: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
85 f.write(b'%s\0%s\0%s\n' % (node, remotepath, name)) |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
86 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
87 f.close() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
88 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
89 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
90 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
|
91 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
92 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
|
93 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
|
94 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
95 wlock = repo.wlock() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
96 try: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
97 if bookmarks: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 writeremotenamefile(repo, remotepath, bookmarks, b'bookmarks') |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
99 if branches: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 writeremotenamefile(repo, remotepath, branches, b'branches') |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
101 finally: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
102 wlock.release() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
103 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
104 |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
105 def activepath(repo, remote): |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
106 """returns remote path""" |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
107 # 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
|
108 local = remote.local() |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
109 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
110 # 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
|
111 # 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
|
112 rpath = remote |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
113 if local: |
40420
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
114 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
|
115 elif not isinstance(remote, bytes): |
49760
5bceea1a8234
logexchange: use the proper accessors to get the remote url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
116 rpath = remote.url() |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
117 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
118 # represent the remotepath with user defined path name if exists |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
119 for path, url in repo.ui.configitems(b'paths'): |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
120 # remove auth info from user defined url |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
121 noauthurl = urlutil.removeauth(url) |
40420
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
122 |
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
123 # 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
|
124 # 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
|
125 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
|
126 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
|
127 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
|
128 rpath = path |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
129 break |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
130 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
131 return rpath |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
132 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
133 |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
134 def pullremotenames(localrepo, remoterepo): |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
135 """ |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
136 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
|
137 pull or clone operation. |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
138 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
|
139 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
|
140 """ |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
141 remotepath = activepath(localrepo, remoterepo) |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
142 |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
143 with remoterepo.commandexecutor() as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
144 bookmarks = e.callcommand( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
145 b'listkeys', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
146 { |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
147 b'namespace': b'bookmarks', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
148 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
149 ).result() |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
150 |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
151 # 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
|
152 # 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
|
153 # 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
|
154 # 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
|
155 bmap = {} |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
156 repo = localrepo.unfiltered() |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
157 |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
158 with remoterepo.commandexecutor() as e: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
159 branchmap = e.callcommand(b'branchmap', {}).result() |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
160 |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
161 for branch, nodes in branchmap.items(): |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
162 bmap[branch] = [] |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
163 for node in nodes: |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
164 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
|
165 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
|
166 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
167 saveremotenames(localrepo, remotepath, bmap, bookmarks) |