Mercurial > hg
annotate mercurial/logexchange.py @ 47995:e7d0a511965c
dirstate: drop the `_addpath` method
All user have been migrated.
Differential Revision: https://phab.mercurial-scm.org/D11435
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 15 Sep 2021 12:38:56 +0200 |
parents | ffd3e823a7e5 |
children | 6000f5b25c9b |
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 ( |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
14 pycompat, |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
15 util, |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
16 vfs as vfsmod, |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
17 ) |
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
|
18 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
|
19 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
|
20 ) |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
21 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
22 # 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
|
23 remotenamedir = b'logexchange' |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
24 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
25 |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
26 def readremotenamefile(repo, filename): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
27 """ |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
32 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
33 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
|
34 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
|
35 return |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
36 f = vfs(filename) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
37 lineno = 0 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
38 for line in f: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
39 line = line.strip() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
40 if not line: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
41 continue |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
42 # contains the version number |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
43 if lineno == 0: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
44 lineno += 1 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
45 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
46 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
|
47 yield node, remote, rname |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
48 except ValueError: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
49 pass |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
50 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
51 f.close() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
52 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
53 |
35239
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
54 def readremotenames(repo): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
55 """ |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35240
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 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
|
60 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
61 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 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
|
63 yield bmentry |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
64 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
|
65 yield branchentry |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35237
diff
changeset
|
66 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
67 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 # 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
|
72 # 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
|
73 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
|
74 |
35240
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
75 olddata = set(readremotenamefile(repo, nametype)) |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35239
diff
changeset
|
76 # 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
|
77 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
|
78 if oldpath != remotepath: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 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
|
80 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
81 for name, node in sorted(pycompat.iteritems(names)): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 if nametype == b"branches": |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
83 for n in node: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
84 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
|
85 elif nametype == b"bookmarks": |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
86 if node: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
87 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
|
88 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
89 f.close() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
90 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
91 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
92 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
|
93 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
94 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
|
95 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
|
96 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
97 wlock = repo.wlock() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
98 try: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
99 if bookmarks: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 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
|
101 if branches: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 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
|
103 finally: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
104 wlock.release() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
105 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
106 |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
107 def activepath(repo, remote): |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
108 """returns remote path""" |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
109 # 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
|
110 local = remote.local() |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
111 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
112 # 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
|
113 # 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
|
114 rpath = remote |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
115 if local: |
40420
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
116 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
|
117 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
|
118 rpath = remote._url |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
119 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
120 # 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
|
121 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
|
122 # 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
|
123 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
|
124 |
94c0421d67a0
logexchange: convert paths to unix when detecting the active path
Matt Harbison <matt_harbison@yahoo.com>
parents:
37981
diff
changeset
|
125 # 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
|
126 # 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
|
127 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
|
128 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
|
129 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
|
130 rpath = path |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
131 break |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
132 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
133 return rpath |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
134 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
135 |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
136 def pullremotenames(localrepo, remoterepo): |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
137 """ |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
138 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
|
139 pull or clone operation. |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
140 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
|
141 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
|
142 """ |
36059
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35347
diff
changeset
|
143 remotepath = activepath(localrepo, remoterepo) |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
144 |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
145 with remoterepo.commandexecutor() as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
146 bookmarks = e.callcommand( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
147 b'listkeys', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
148 { |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
149 b'namespace': b'bookmarks', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43106
diff
changeset
|
150 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
151 ).result() |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
152 |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
153 # 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
|
154 # 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
|
155 # 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
|
156 # 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
|
157 bmap = {} |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
158 repo = localrepo.unfiltered() |
37639
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
159 |
0e50dda7e9c1
logexchange: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37365
diff
changeset
|
160 with remoterepo.commandexecutor() as e: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
161 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
|
162 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
163 for branch, nodes in pycompat.iteritems(branchmap): |
35236
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
164 bmap[branch] = [] |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
165 for node in nodes: |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
166 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
|
167 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
|
168 |
35237
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35236
diff
changeset
|
169 saveremotenames(localrepo, remotepath, bmap, bookmarks) |