Mercurial > hg
annotate mercurial/discovery.py @ 13872:e6bd5b403de0
localrepo: tighten except clause when looking rev
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Mon, 04 Apr 2011 18:05:14 +0300 |
parents | 7abab875e647 |
children | 72c84f24b420 |
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 # |
11313
0bb14798cd07
discovery: fix description line
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11301
diff
changeset
|
3 # Copyright 2010 Matt Mackall <mpm@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 | 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 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
8 from node import nullid, short |
3891 | 9 from i18n import _ |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
10 import util, error |
8109
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
8108
diff
changeset
|
11 |
13742
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
12 def findcommonincoming(repo, remote, heads=None, force=False, commononly=False): |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
13 """Return a tuple (common, missing, heads) used to identify missing nodes |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
14 from remote. "missing" is either a boolean indicating if any nodes are missing |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
15 (when commononly=True), or else a list of the root nodes of the missing set. |
2601
00fc88b0b256
move most of tag code to localrepository class.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2581
diff
changeset
|
16 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
17 If a list of heads is specified, return only nodes which are heads |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
18 or ancestors of these heads. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
19 """ |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
20 m = repo.changelog.nodemap |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
21 search = [] |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
22 fetch = set() |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
23 seen = set() |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
24 seenbranch = set() |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
25 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
|
26 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
27 if not heads: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
28 heads = remote.heads() |
343 | 29 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
30 if repo.changelog.tip() == nullid: |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
31 base.add(nullid) |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
32 if heads != [nullid]: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
33 return [nullid], [nullid], list(heads) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
34 return [nullid], [], [] |
3826
b3b868113d24
fix encoding conversion of branch names when mq is loaded
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3803
diff
changeset
|
35 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
36 # 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
|
37 # and start by examining the heads |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
38 repo.ui.status(_("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
|
39 |
13742
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
40 if commononly: |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
41 myheads = repo.heads() |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
42 known = remote.known(myheads) |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
43 if util.all(known): |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
44 hasincoming = set(heads).difference(set(myheads)) and True |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
45 return myheads, hasincoming, heads |
7abab875e647
discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12998
diff
changeset
|
46 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
47 unknown = [] |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
48 for h in heads: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
49 if h not in m: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
50 unknown.append(h) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
51 else: |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
52 base.add(h) |
7654
816b708f23af
store all heads of a branch in the branch cache
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
7644
diff
changeset
|
53 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
54 heads = unknown |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
55 if not unknown: |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
56 return list(base), [], [] |
4415
1a63b44f90c9
branch.cache: silently ignore I/O and OS errors
Matt Mackall <mpm@selenic.com>
parents:
4329
diff
changeset
|
57 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
58 req = set(unknown) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
59 reqcnt = 0 |
3417
028fff46a4ac
Add branchtags function with cache
Matt Mackall <mpm@selenic.com>
parents:
3377
diff
changeset
|
60 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
61 # search through remote branches |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
62 # 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
|
63 # 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
|
64 # (a branch always has two parents (or none) by definition) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
65 unknown = remote.branches(unknown) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
66 while unknown: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
67 r = [] |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
68 while unknown: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
69 n = unknown.pop(0) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
70 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
|
71 continue |
1806
a2c69737e65e
Automatic nesting into running transactions in the same repository.
mason@suse.com
parents:
1802
diff
changeset
|
72 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
73 repo.ui.debug("examining %s:%s\n" |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
74 % (short(n[0]), short(n[1]))) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
75 if n[0] == nullid: # found the end of the branch |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
76 pass |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
77 elif n in seenbranch: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
78 repo.ui.debug("branch already found\n") |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
79 continue |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
80 elif n[1] and n[1] in m: # do we know the base? |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
81 repo.ui.debug("found incomplete branch %s:%s\n" |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
82 % (short(n[0]), short(n[1]))) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
83 search.append(n[0:2]) # schedule branch range for scanning |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
84 seenbranch.add(n) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4914
diff
changeset
|
85 else: |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
86 if n[1] not in seen and n[1] not in fetch: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
87 if n[2] in m and n[3] in m: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
88 repo.ui.debug("found new changeset %s\n" % |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
89 short(n[1])) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
90 fetch.add(n[1]) # earliest unknown |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
91 for p in n[2:4]: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
92 if p in m: |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
93 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
|
94 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
95 for p in n[2:4]: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
96 if p not in req and p not in m: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
97 r.append(p) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
98 req.add(p) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
99 seen.add(n[0]) |
1716
ef8cd889a78b
Refactor excessive merge detection, add test
Matt Mackall <mpm@selenic.com>
parents:
1713
diff
changeset
|
100 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
101 if r: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
102 reqcnt += 1 |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
103 repo.ui.progress(_('searching'), reqcnt, unit=_('queries')) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
104 repo.ui.debug("request %d: %s\n" % |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
105 (reqcnt, " ".join(map(short, r)))) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
106 for p in xrange(0, len(r), 10): |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
107 for b in remote.branches(r[p:p + 10]): |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
108 repo.ui.debug("received %s:%s\n" % |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
109 (short(b[0]), short(b[1]))) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
110 unknown.append(b) |
8404
a2bc39ade36b
commit: move 'nothing changed' test into commit()
Matt Mackall <mpm@selenic.com>
parents:
8403
diff
changeset
|
111 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
112 # 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
|
113 while search: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
114 newsearch = [] |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
115 reqcnt += 1 |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
116 repo.ui.progress(_('searching'), reqcnt, unit=_('queries')) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
117 for n, l in zip(search, remote.between(search)): |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
118 l.append(n[1]) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
119 p = n[0] |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
120 f = 1 |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
121 for i in l: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
122 repo.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
123 if i in m: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
124 if f <= 2: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
125 repo.ui.debug("found new branch changeset %s\n" % |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
126 short(p)) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
127 fetch.add(p) |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
128 base.add(i) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4914
diff
changeset
|
129 else: |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
130 repo.ui.debug("narrowed branch search to %s:%s\n" |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
131 % (short(p), short(i))) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
132 newsearch.append((p, i)) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
133 break |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
134 p, f = i, f * 2 |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
135 search = newsearch |
9150
09a1ee498756
localrepo: add destroyed() method for strip/rollback to use (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
136 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
137 # sanity check our fetch list |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
138 for f in fetch: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
139 if f in m: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
140 raise error.RepoError(_("already have changeset ") |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
141 + short(f[:4])) |
4912
312c845edef5
simplify dirstate fixups in repo.status()
Matt Mackall <mpm@selenic.com>
parents:
4910
diff
changeset
|
142 |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
143 base = list(base) |
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
144 if base == [nullid]: |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
145 if force: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
146 repo.ui.warn(_("warning: repository is unrelated\n")) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
147 else: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
148 raise util.Abort(_("repository is unrelated")) |
4372
4ddc6d374265
localrepository.status: only acquire wlock if actually needed.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4335
diff
changeset
|
149 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
150 repo.ui.debug("found new changesets starting at " + |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
151 " ".join([short(f) for f in fetch]) + "\n") |
2661
5c10b7ed3411
status: add -c (clean) and -A (all files) options
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2621
diff
changeset
|
152 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
153 repo.ui.progress(_('searching'), None) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
154 repo.ui.debug("%d total queries\n" % reqcnt) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
155 |
12761
11c3c77da62a
discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12760
diff
changeset
|
156 return base, list(fetch), heads |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
157 |
11576
98c874a929f1
discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11574
diff
changeset
|
158 def findoutgoing(repo, remote, base=None, remoteheads=None, force=False): |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
159 """Return list of nodes that are roots of subsets not in remote |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
160 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
161 If base dict is specified, assume that these nodes and their parents |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
162 exist on the remote side. |
11576
98c874a929f1
discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11574
diff
changeset
|
163 If remotehead is specified, assume it is the list of the heads from |
98c874a929f1
discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11574
diff
changeset
|
164 the remote repository. |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
165 """ |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
166 if base is None: |
12759
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
167 base = findcommonincoming(repo, remote, heads=remoteheads, |
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
168 force=force)[0] |
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
169 else: |
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
170 base = list(base) |
2339
11422943cf72
document and fix findincoming
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2335
diff
changeset
|
171 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
172 repo.ui.debug("common changesets up to " |
12759
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
173 + " ".join(map(short, base)) + "\n") |
2108
30c7564f6dfc
Move empty local repo logic for pull into findincoming
Matt Mackall <mpm@selenic.com>
parents:
2107
diff
changeset
|
174 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
175 remain = set(repo.changelog.nodemap) |
148
c32286d0a665
Improve pruning of branches in outstanding changeset algorithm
mpm@selenic.com
parents:
146
diff
changeset
|
176 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
177 # prune everything remote has from the tree |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
178 remain.remove(nullid) |
12759
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
179 remove = base |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
180 while remove: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
181 n = remove.pop(0) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
182 if n in remain: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
183 remain.remove(n) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
184 for p in repo.changelog.parents(n): |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
185 remove.append(p) |
65
d40cc5aacc31
Fix up a bunch of bugs in the new merge code
mpm@selenic.com
parents:
64
diff
changeset
|
186 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
187 # find every node whose parents have been pruned |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
188 subset = [] |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
189 # find every remote head that will get new children |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
190 for n in remain: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
191 p1, p2 = repo.changelog.parents(n) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
192 if p1 not in remain and p2 not in remain: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
193 subset.append(n) |
7415
6163ef936a00
protocol: use changegroupsubset() if possible (issue1389)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7377
diff
changeset
|
194 |
11576
98c874a929f1
discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11574
diff
changeset
|
195 return subset |
3684
975c2469c316
correct remote heads test in prepush
Matt Mackall <mpm@selenic.com>
parents:
3682
diff
changeset
|
196 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
197 def prepush(repo, remote, force, revs, newbranch): |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
198 '''Analyze the local and remote repositories and determine which |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
199 changesets need to be pushed to the remote. Return value depends |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
200 on circumstances: |
10353
36b6b5ef7820
prepush: rename variables, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10327
diff
changeset
|
201 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
202 If we are not going to push anything, return a tuple (None, |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
203 outgoing) where outgoing is 0 if there are no outgoing |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
204 changesets and 1 if there are, but we refuse to push them |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
205 (e.g. would create new remote heads). |
3684
975c2469c316
correct remote heads test in prepush
Matt Mackall <mpm@selenic.com>
parents:
3682
diff
changeset
|
206 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
207 Otherwise, return a tuple (changegroup, remoteheads), where |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
208 changegroup is a readable file-like object whose read() returns |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
209 successive changegroup chunks ready to be sent over the wire and |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
210 remoteheads is the list of remote heads.''' |
11577
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
211 remoteheads = remote.heads() |
12759
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
212 common, inc, rheads = findcommonincoming(repo, remote, heads=remoteheads, |
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
213 force=force) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2424
diff
changeset
|
214 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
215 cl = repo.changelog |
11577
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
216 update = findoutgoing(repo, remote, common, remoteheads) |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
217 outg, bases, heads = cl.nodesbetween(update, revs) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2424
diff
changeset
|
218 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
219 if not bases: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
220 repo.ui.status(_("no changes found\n")) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
221 return None, 1 |
622
e9fe5d5e67f7
Add generic repo commands for pull and push
Matt Mackall <mpm@selenic.com>
parents:
621
diff
changeset
|
222 |
11577
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
223 if not force and remoteheads != [nullid]: |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
224 if remote.capable('branchmap'): |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
225 # Check for each named branch if we're creating new remote heads. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
226 # To be a remote head after push, node must be either: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
227 # - unknown locally |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
228 # - a local outgoing head descended from update |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
229 # - a remote head that's known locally and not |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
230 # ancestral to an outgoing head |
10405
2d30d66a89ad
whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
10396
diff
changeset
|
231 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
232 # 1. Create set of branches involved in the push. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
233 branches = set(repo[n].branch() for n in outg) |
1466
b6d9ea0bc107
Added a lot of comments to changegroupsubset.
Eric Hopper <hopper@omnifarious.org>
parents:
1464
diff
changeset
|
234 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
235 # 2. Check for new branches on the remote. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
236 remotemap = remote.branchmap() |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
237 newbranches = branches - set(remotemap) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
238 if newbranches and not newbranch: # new branch requires --new-branch |
11429
d420ff348c49
discovery: use stable sort order in --new-branch warning
Martin Geisler <mg@aragost.com>
parents:
11313
diff
changeset
|
239 branchnames = ', '.join(sorted(newbranches)) |
11574
6381fa7bfa53
Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11573
diff
changeset
|
240 raise util.Abort(_("push creates new remote branches: %s!") |
6381fa7bfa53
Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11573
diff
changeset
|
241 % branchnames, |
6381fa7bfa53
Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11573
diff
changeset
|
242 hint=_("use 'hg push --new-branch' to create" |
6381fa7bfa53
Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11573
diff
changeset
|
243 " new remote branches")) |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
244 branches.difference_update(newbranches) |
1458
1033892bbb87
This changes the revlog.group and re-implements the localrepo.changeroup
Eric Hopper <hopper@omnifarious.org>
parents:
1457
diff
changeset
|
245 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
246 # 3. Construct the initial oldmap and newmap dicts. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
247 # They contain information about the remote heads before and |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
248 # after the push, respectively. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
249 # Heads not found locally are not included in either dict, |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
250 # since they won't be affected by the push. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
251 # unsynced contains all branches with incoming changesets. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
252 oldmap = {} |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
253 newmap = {} |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
254 unsynced = set() |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
255 for branch in branches: |
11577
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
256 remotebrheads = remotemap[branch] |
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
257 prunedbrheads = [h for h in remotebrheads if h in cl.nodemap] |
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
258 oldmap[branch] = prunedbrheads |
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
259 newmap[branch] = list(prunedbrheads) |
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
260 if len(remotebrheads) > len(prunedbrheads): |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
261 unsynced.add(branch) |
635
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
634
diff
changeset
|
262 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
263 # 4. Update newmap with outgoing changes. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
264 # This will possibly add new heads and remove existing ones. |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
265 ctxgen = (repo[n] for n in outg) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
266 repo._updatebranchcache(newmap, ctxgen) |
1998
65cc17ae9649
fix race in localrepo.addchangegroup.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1995
diff
changeset
|
267 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
268 else: |
11578
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
269 # 1-4b. old servers: Check for new topological heads. |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
270 # Construct {old,new}map with branch = None (topological branch). |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
271 # (code based on _updatebranchcache) |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
272 oldheads = set(h for h in remoteheads if h in cl.nodemap) |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
273 newheads = oldheads.union(outg) |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
274 if len(newheads) > 1: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
275 for latest in reversed(outg): |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
276 if latest not in newheads: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
277 continue |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
278 minhrev = min(cl.rev(h) for h in newheads) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
279 reachable = cl.reachable(latest, cl.node(minhrev)) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
280 reachable.remove(latest) |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
281 newheads.difference_update(reachable) |
11578
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
282 branches = set([None]) |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
283 newmap = {None: newheads} |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
284 oldmap = {None: oldheads} |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
285 unsynced = inc and branches or set() |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
286 |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
287 # 5. Check for new heads. |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
288 # If there are more heads after the push than before, a suitable |
12998
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
289 # error message, depending on unsynced status, is displayed. |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
290 error = None |
11578
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
291 for branch in branches: |
12998
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
292 newhs = set(newmap[branch]) |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
293 oldhs = set(oldmap[branch]) |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
294 if len(newhs) > len(oldhs): |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
295 if error is None: |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
296 if branch: |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
297 error = _("push creates new remote heads " |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
298 "on branch '%s'!") % branch |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
299 else: |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
300 error = _("push creates new remote heads!") |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
301 if branch in unsynced: |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
302 hint = _("you should pull and merge or " |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
303 "use push -f to force") |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
304 else: |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
305 hint = _("did you forget to merge? " |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
306 "use push -f to force") |
11578
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
307 if branch: |
12998
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
308 repo.ui.debug("new remote heads on branch '%s'\n" % branch) |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
309 for h in (newhs - oldhs): |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
310 repo.ui.debug("new remote head %s\n" % short(h)) |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
311 if error: |
91cb08a9e7fb
discovery: list new remote heads in prepush() on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents:
12997
diff
changeset
|
312 raise util.Abort(error, hint=hint) |
11578
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
313 |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
314 # 6. Check for unsynced changes on involved branches. |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
315 if unsynced: |
bb7af1de5e38
discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11577
diff
changeset
|
316 repo.ui.warn(_("note: unsynced remote changes!\n")) |
515 | 317 |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
318 if revs is None: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
319 # use the fast path, no race possible on push |
12759
9c5794223340
discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11578
diff
changeset
|
320 nodes = repo.changelog.findmissing(common) |
11301
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
321 cg = repo._changegroup(nodes, 'push') |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
322 else: |
3d0591a66118
move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11230
diff
changeset
|
323 cg = repo.changegroupsubset(update, revs, 'push') |
11577
0bc450253312
discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11576
diff
changeset
|
324 return cg, remoteheads |