Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/logexchange.py @ 37060:2ec1fb9de638
wireproto: add request IDs to frames
One of my primary goals with the new wire protocol is to make
operations faster and enable both client and server-side
operations to scale to multiple CPU cores.
One of the ways we make server interactions faster is by reducing
the number of round trips to that server.
With the existing wire protocol, the "batch" command facilitates
executing multiple commands from a single request payload. The way
it works is the requests for multiple commands are serialized. The
server executes those commands sequentially then serializes all
their results. As an optimization for reducing round trips, this
is very effective. The technical implementation, however, is pretty
bad and suffers from a number of deficiencies. For example, it
creates a new place where authorization to run a command must be
checked. (The lack of this checking in older Mercurial releases
was CVE-2018-1000132.)
The principles behind the "batch" command are sound. However, the
execution is not. Therefore, I want to ditch "batch" in the
new wire protocol and have protocol level support for issuing
multiple requests in a single round trip.
This commit introduces support in the frame-based wire protocol to
facilitate this. We do this by adding a "request ID" to each frame.
If a server sees frames associated with different "request IDs," it
handles them as separate requests. All of this happening possibly
as part of the same message from client to server (the same request
body in the case of HTTP).
We /could/ model the exchange the way pipelined HTTP requests do,
where the server processes requests in order they are issued and
received. But this artifically constrains scalability. A better
model is to allow multi-requests to be executed concurrently and
for responses to be sent and handled concurrently. So the
specification explicitly allows this. There is some work to be done
around specifying dependencies between multi-requests. We take
the easy road for now and punt on this problem, declaring that
if order is important, clients must not issue the request until
responses to dependent requests have been received.
This commit focuses on the boilerplate of implementing the request
ID. The server reactor still can't manage multiple, in-flight
request IDs. This will be addressed in a subsequent commit.
Because the wire semantics have changed, we bump the version of the
media type.
Differential Revision: https://phab.mercurial-scm.org/D2869
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 14 Mar 2018 16:51:34 -0700 |
parents | 62a428bf6359 |
children | 1ccd75027abb |
rev | line source |
---|---|
35356
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
1 # logexchange.py |
35245
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 |
35246
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
13 from . import ( |
36097
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
14 util, |
35246
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
15 vfs as vfsmod, |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
16 ) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
17 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
18 # directory name in .hg/ in which remotenames files will be present |
35356
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
19 remotenamedir = 'logexchange' |
35246
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
20 |
35248
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
21 def readremotenamefile(repo, filename): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
22 """ |
35356
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
23 reads a file from .hg/logexchange/ directory and yields it's content |
35248
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
24 filename: the file to be read |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
25 yield a tuple (node, remotepath, name) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
26 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
27 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
28 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
29 if not vfs.exists(filename): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
30 return |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
31 f = vfs(filename) |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
32 lineno = 0 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
33 for line in f: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
34 line = line.strip() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
35 if not line: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
36 continue |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
37 # contains the version number |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
38 if lineno == 0: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
39 lineno += 1 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
40 try: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
41 node, remote, rname = line.split('\0') |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
42 yield node, remote, rname |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
43 except ValueError: |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
44 pass |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
45 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
46 f.close() |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
47 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
48 def readremotenames(repo): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
49 """ |
35356
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
50 read the details about the remotenames stored in .hg/logexchange/ and |
35248
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
51 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:
35246
diff
changeset
|
52 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:
35246
diff
changeset
|
53 information, call the respective functions. |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
54 """ |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
55 |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
56 for bmentry in readremotenamefile(repo, 'bookmarks'): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
57 yield bmentry |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
58 for branchentry in readremotenamefile(repo, 'branches'): |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
59 yield branchentry |
744d1c874a59
remotenames: add functions to read remotenames data from .hg/remotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35246
diff
changeset
|
60 |
35246
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
61 def writeremotenamefile(repo, remotepath, names, nametype): |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
62 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
63 f = vfs(nametype, 'w', atomictemp=True) |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
64 # 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:
35245
diff
changeset
|
65 # 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:
35245
diff
changeset
|
66 f.write('0\n\n') |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
67 |
35249
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35248
diff
changeset
|
68 olddata = set(readremotenamefile(repo, nametype)) |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35248
diff
changeset
|
69 # 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:
35248
diff
changeset
|
70 for node, oldpath, rname in sorted(olddata): |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35248
diff
changeset
|
71 if oldpath != remotepath: |
2ea6e42ed15e
remotenames: consider existing data while storing newer data
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35248
diff
changeset
|
72 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:
35248
diff
changeset
|
73 |
35246
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
74 for name, node in sorted(names.iteritems()): |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
75 if nametype == "branches": |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
76 for n in node: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
77 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:
35245
diff
changeset
|
78 elif nametype == "bookmarks": |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
79 if node: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
80 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:
35245
diff
changeset
|
81 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
82 f.close() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
83 |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
84 def saveremotenames(repo, remotepath, branches=None, bookmarks=None): |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
85 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
86 save remotenames i.e. remotebookmarks and remotebranches in their |
35356
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
87 respective files under ".hg/logexchange/" directory. |
35246
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
88 """ |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
89 wlock = repo.wlock() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
90 try: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
91 if bookmarks: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
92 writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
93 if branches: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
94 writeremotenamefile(repo, remotepath, branches, 'branches') |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
95 finally: |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
96 wlock.release() |
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
97 |
36097
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
98 def activepath(repo, remote): |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
99 """returns remote path""" |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
100 local = None |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
101 # is the remote a local peer |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
102 local = remote.local() |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
103 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
104 # 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:
35356
diff
changeset
|
105 # use the string given to us |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
106 rpath = remote |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
107 if local: |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
108 rpath = remote._repo.root |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
109 elif not isinstance(remote, str): |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
110 rpath = remote._url |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
111 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
112 # 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:
35356
diff
changeset
|
113 for path, url in repo.ui.configitems('paths'): |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
114 # remove auth info from user defined url |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
115 url = util.removeauth(url) |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
116 if url == rpath: |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
117 rpath = path |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
118 break |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
119 |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
120 return rpath |
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
121 |
35245
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
122 def pullremotenames(localrepo, remoterepo): |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
123 """ |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
124 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
|
125 pull or clone operation. |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
126 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
|
127 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
|
128 """ |
36097
62a428bf6359
logexchange: introduce helper function to get remote path name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35356
diff
changeset
|
129 remotepath = activepath(localrepo, remoterepo) |
35245
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
130 bookmarks = remoterepo.listkeys('bookmarks') |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
131 # 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
|
132 # 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
|
133 # 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
|
134 # 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
|
135 bmap = {} |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
136 repo = localrepo.unfiltered() |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
137 for branch, nodes in remoterepo.branchmap().iteritems(): |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
138 bmap[branch] = [] |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
139 for node in nodes: |
5a62910948d2
remotenames: move function to pull remotenames from the remoterepo to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
140 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
|
141 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
|
142 |
35246
8df8ce2cc5dd
remotenames: add functionality to store remotenames under .hg/hgremotenames/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35245
diff
changeset
|
143 saveremotenames(localrepo, remotepath, bmap, bookmarks) |