annotate mercurial/treediscovery.py @ 50066:ebb8648483db

rollback: show that the safety works in a associated test That test section is checking that --force is overcoming the safety check, however we did not check that the safety properly detect the situation. We now do for clarity.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Feb 2023 20:47:08 +0100
parents f64f66167afc
children f4733654f144
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11313
0bb14798cd07 discovery: fix description line
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11301
diff changeset
1 # discovery.py - protocol changeset discovery functions
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
2 #
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46110
diff changeset
3 # Copyright 2010 Olivia Mackall <olivia@selenic.com>
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8210
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9954
diff changeset
6 # GNU General Public License version 2 or any later version.
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
7
25987
c6d049a5de43 treediscovery: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
8
25113
0ca8410ea345 util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents: 20225
diff changeset
9 import collections
25987
c6d049a5de43 treediscovery: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
10
c6d049a5de43 treediscovery: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
11 from .i18n import _
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
12 from .node import short
25987
c6d049a5de43 treediscovery: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
13 from . import (
c6d049a5de43 treediscovery: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
14 error,
c6d049a5de43 treediscovery: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
15 )
8109
496ae1ea4698 switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8108
diff changeset
16
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
17
46110
d90f439ff19f debugdiscovery: display the number of roundtrip used
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
18 def findcommonincoming(repo, remote, heads=None, force=False, audit=None):
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
19 """Return a tuple (common, fetch, heads) used to identify the common
14073
72c84f24b420 discovery: drop findoutgoing and simplify findcommonincoming's api
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13742
diff changeset
20 subset of nodes between repo and remote.
2601
00fc88b0b256 move most of tag code to localrepository class.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2581
diff changeset
21
14073
72c84f24b420 discovery: drop findoutgoing and simplify findcommonincoming's api
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13742
diff changeset
22 "common" is a list of (at least) the heads of the common subset.
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
23 "fetch" is a list of roots of the nodes that would be incoming, to be
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
24 supplied to changegroupsubset.
14073
72c84f24b420 discovery: drop findoutgoing and simplify findcommonincoming's api
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13742
diff changeset
25 "heads" is either the supplied heads, or else the remote's heads.
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
26 """
14073
72c84f24b420 discovery: drop findoutgoing and simplify findcommonincoming's api
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13742
diff changeset
27
20225
d2704c48f417 discovery: stop using nodemap for membership testing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16834
diff changeset
28 knownnode = repo.changelog.hasnode
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
29 search = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
30 fetch = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
31 seen = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
32 seenbranch = set()
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
33 base = set()
5657
47915bf68c44 Properly check tag's existence as a local/global tag when removing it.
Osku Salerma <osku@iki.fi>
parents: 5637
diff changeset
34
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
35 if not heads:
37634
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
36 with remote.commandexecutor() as e:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
37 heads = e.callcommand(b'heads', {}).result()
343
d7df759d0e97 rework all code using tags
mpm@selenic.com
parents: 337
diff changeset
38
46110
d90f439ff19f debugdiscovery: display the number of roundtrip used
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
39 if audit is not None:
d90f439ff19f debugdiscovery: display the number of roundtrip used
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
40 audit[b'total-roundtrips'] = 1
49402
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
41 audit[b'total-roundtrips-heads'] = 1
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
42 audit[b'total-roundtrips-branches'] = 0
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
43 audit[b'total-roundtrips-between'] = 0
49017
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
44 audit[b'total-queries'] = 0
49401
362c0026a977 debug-discovery: also gather details on tree-discovery queries type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
45 audit[b'total-queries-branches'] = 0
362c0026a977 debug-discovery: also gather details on tree-discovery queries type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
46 audit[b'total-queries-between'] = 0
46110
d90f439ff19f debugdiscovery: display the number of roundtrip used
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
47
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
48 if repo.changelog.tip() == repo.nullid:
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
49 base.add(repo.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
50 if heads != [repo.nullid]:
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
51 return [repo.nullid], [repo.nullid], list(heads)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
52 return [repo.nullid], [], heads
3826
b3b868113d24 fix encoding conversion of branch names when mq is loaded
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3803
diff changeset
53
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
54 # assume we're closer to the tip than the root
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
55 # and start by examining the heads
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
56 repo.ui.status(_(b"searching for changes\n"))
6121
7336aeff1a1d automatically update the branch cache when tip changes
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6120
diff changeset
57
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
58 unknown = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
59 for h in heads:
20225
d2704c48f417 discovery: stop using nodemap for membership testing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16834
diff changeset
60 if not knownnode(h):
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
61 unknown.append(h)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
62 else:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
63 base.add(h)
7654
816b708f23af store all heads of a branch in the branch cache
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 7644
diff changeset
64
14199
e3dd3dcd6059 treediscovery: fix regression when run against older repos (issue2793)
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14164
diff changeset
65 if not unknown:
e3dd3dcd6059 treediscovery: fix regression when run against older repos (issue2793)
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14164
diff changeset
66 return list(base), [], list(heads)
e3dd3dcd6059 treediscovery: fix regression when run against older repos (issue2793)
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14164
diff changeset
67
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
68 req = set(unknown)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
69 reqcnt = 0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
70 progress = repo.ui.makeprogress(_(b'searching'), unit=_(b'queries'))
3417
028fff46a4ac Add branchtags function with cache
Matt Mackall <mpm@selenic.com>
parents: 3377
diff changeset
71
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
72 # search through remote branches
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
73 # a 'branch' here is a linear segment of history, with four parts:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
74 # head, root, first parent, second parent
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
75 # (a branch always has two parents (or none) by definition)
37634
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
76 with remote.commandexecutor() as e:
49017
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
77 if audit is not None:
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
78 audit[b'total-queries'] += len(unknown)
49401
362c0026a977 debug-discovery: also gather details on tree-discovery queries type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
79 audit[b'total-queries-branches'] += len(unknown)
49402
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
80 audit[b'total-roundtrips'] += 1
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
81 audit[b'total-roundtrips-branches'] += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
82 branches = e.callcommand(b'branches', {b'nodes': unknown}).result()
37634
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
83
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
84 unknown = collections.deque(branches)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
85 while unknown:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
86 r = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
87 while unknown:
16803
107a3270a24a cleanup: use the deque type where appropriate
Bryan O'Sullivan <bryano@fb.com>
parents: 14698
diff changeset
88 n = unknown.popleft()
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
89 if n[0] in seen:
8954
e67e5b60e55f Branch heads should not include "heads" that are ancestors of other heads.
Brendan Cully <brendan@kublai.com>
parents: 8916
diff changeset
90 continue
1806
a2c69737e65e Automatic nesting into running transactions in the same repository.
mason@suse.com
parents: 1802
diff changeset
91
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
92 repo.ui.debug(b"examining %s:%s\n" % (short(n[0]), short(n[1])))
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
93 if n[0] == repo.nullid: # found the end of the branch
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
94 pass
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
95 elif n in seenbranch:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
96 repo.ui.debug(b"branch already found\n")
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
97 continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
98 elif n[1] and knownnode(n[1]): # do we know the base?
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
99 repo.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
100 b"found incomplete branch %s:%s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
101 % (short(n[0]), short(n[1]))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
102 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
103 search.append(n[0:2]) # schedule branch range for scanning
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
104 seenbranch.add(n)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4914
diff changeset
105 else:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
106 if n[1] not in seen and n[1] not in fetch:
20225
d2704c48f417 discovery: stop using nodemap for membership testing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16834
diff changeset
107 if knownnode(n[2]) and knownnode(n[3]):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
108 repo.ui.debug(b"found new changeset %s\n" % short(n[1]))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
109 fetch.add(n[1]) # earliest unknown
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
110 for p in n[2:4]:
20225
d2704c48f417 discovery: stop using nodemap for membership testing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16834
diff changeset
111 if knownnode(p):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
112 base.add(p) # latest known
1531
2ba8bf7defda add localrepo.wlock for protecting the dirstate
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1516
diff changeset
113
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
114 for p in n[2:4]:
20225
d2704c48f417 discovery: stop using nodemap for membership testing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16834
diff changeset
115 if p not in req and not knownnode(p):
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
116 r.append(p)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
117 req.add(p)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
118 seen.add(n[0])
1716
ef8cd889a78b Refactor excessive merge detection, add test
Matt Mackall <mpm@selenic.com>
parents: 1713
diff changeset
119
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
120 if r:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49017
diff changeset
121 for p in range(0, len(r), 10):
49405
f64f66167afc tree-discovery: fix the request debug output and progress location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49402
diff changeset
122 reqcnt += 1
f64f66167afc tree-discovery: fix the request debug output and progress location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49402
diff changeset
123 progress.increment()
f64f66167afc tree-discovery: fix the request debug output and progress location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49402
diff changeset
124 if repo.ui.debugflag:
f64f66167afc tree-discovery: fix the request debug output and progress location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49402
diff changeset
125 msg = b"request %d: %s\n"
f64f66167afc tree-discovery: fix the request debug output and progress location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49402
diff changeset
126 msg %= (reqcnt, b" ".join(map(short, r)))
f64f66167afc tree-discovery: fix the request debug output and progress location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49402
diff changeset
127 repo.ui.debug(msg)
37634
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
128 with remote.commandexecutor() as e:
49017
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
129 subset = r[p : p + 10]
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
130 if audit is not None:
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
131 audit[b'total-queries'] += len(subset)
49401
362c0026a977 debug-discovery: also gather details on tree-discovery queries type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
132 audit[b'total-queries-branches'] += len(subset)
49402
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
133 audit[b'total-roundtrips'] += 1
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
134 audit[b'total-roundtrips-branches'] += 1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
135 branches = e.callcommand(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43077
diff changeset
136 b'branches',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43077
diff changeset
137 {
49017
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
138 b'nodes': subset,
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43077
diff changeset
139 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
140 ).result()
37634
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
141
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
142 for b in branches:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
143 repo.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
144 b"received %s:%s\n" % (short(b[0]), short(b[1]))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
145 )
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
146 unknown.append(b)
8404
a2bc39ade36b commit: move 'nothing changed' test into commit()
Matt Mackall <mpm@selenic.com>
parents: 8403
diff changeset
147
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
148 # do binary search on the branches we found
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
149 while search:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
150 newsearch = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
151 reqcnt += 1
38400
2f5c622fcb73 treediscovery: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 37634
diff changeset
152 progress.increment()
37634
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
153
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
154 with remote.commandexecutor() as e:
49017
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
155 if audit is not None:
f054a557aab8 discovery: also audit the number of queries done
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
156 audit[b'total-queries'] += len(search)
49401
362c0026a977 debug-discovery: also gather details on tree-discovery queries type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
157 audit[b'total-queries-between'] += len(search)
49402
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
158 audit[b'total-roundtrips'] += 1
236702592ff0 debug-discovery: gather the right number of roundtrips for tree discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49401
diff changeset
159 audit[b'total-roundtrips-between'] += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
160 between = e.callcommand(b'between', {b'pairs': search}).result()
37634
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
161
0ed11f9368fd treediscovery: switch to command executor interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
162 for n, l in zip(search, between):
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
163 l.append(n[1])
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
164 p = n[0]
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
165 f = 1
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
166 for i in l:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
167 repo.ui.debug(b"narrowing %d:%d %s\n" % (f, len(l), short(i)))
20225
d2704c48f417 discovery: stop using nodemap for membership testing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16834
diff changeset
168 if knownnode(i):
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
169 if f <= 2:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
170 repo.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
171 b"found new branch changeset %s\n" % short(p)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
172 )
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
173 fetch.add(p)
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
174 base.add(i)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4914
diff changeset
175 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
176 repo.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
177 b"narrowed branch search to %s:%s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
178 % (short(p), short(i))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
179 )
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
180 newsearch.append((p, i))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
181 break
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
182 p, f = i, f * 2
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
183 search = newsearch
9150
09a1ee498756 localrepo: add destroyed() method for strip/rollback to use (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
184
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
185 # sanity check our fetch list
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
186 for f in fetch:
20225
d2704c48f417 discovery: stop using nodemap for membership testing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16834
diff changeset
187 if knownnode(f):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
188 raise error.RepoError(_(b"already have changeset ") + short(f[:4]))
4912
312c845edef5 simplify dirstate fixups in repo.status()
Matt Mackall <mpm@selenic.com>
parents: 4910
diff changeset
189
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
190 base = list(base)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
191 if base == [repo.nullid]:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
192 if force:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
193 repo.ui.warn(_(b"warning: repository is unrelated\n"))
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
194 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
195 raise error.Abort(_(b"repository is unrelated"))
4372
4ddc6d374265 localrepository.status: only acquire wlock if actually needed.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4335
diff changeset
196
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
197 repo.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
198 b"found new changesets starting at "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
199 + b" ".join([short(f) for f in fetch])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
200 + b"\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
201 )
2661
5c10b7ed3411 status: add -c (clean) and -A (all files) options
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2621
diff changeset
202
38400
2f5c622fcb73 treediscovery: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 37634
diff changeset
203 progress.complete()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
204 repo.ui.debug(b"%d total queries\n" % reqcnt)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
205
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
206 return base, list(fetch), heads