Show More
@@ -1,348 +1,343 b'' | |||||
1 | # discovery.py - protocol changeset discovery functions |
|
1 | # discovery.py - protocol changeset discovery functions | |
2 | # |
|
2 | # | |
3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import nullid, short |
|
8 | from node import nullid, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import util, setdiscovery, treediscovery, phases, obsolete, bookmarks |
|
10 | import util, setdiscovery, treediscovery, phases, obsolete, bookmarks | |
11 | import branchmap |
|
11 | import branchmap | |
12 |
|
12 | |||
13 | def findcommonincoming(repo, remote, heads=None, force=False): |
|
13 | def findcommonincoming(repo, remote, heads=None, force=False): | |
14 | """Return a tuple (common, anyincoming, heads) used to identify the common |
|
14 | """Return a tuple (common, anyincoming, heads) used to identify the common | |
15 | subset of nodes between repo and remote. |
|
15 | subset of nodes between repo and remote. | |
16 |
|
16 | |||
17 | "common" is a list of (at least) the heads of the common subset. |
|
17 | "common" is a list of (at least) the heads of the common subset. | |
18 | "anyincoming" is testable as a boolean indicating if any nodes are missing |
|
18 | "anyincoming" is testable as a boolean indicating if any nodes are missing | |
19 | locally. If remote does not support getbundle, this actually is a list of |
|
19 | locally. If remote does not support getbundle, this actually is a list of | |
20 | roots of the nodes that would be incoming, to be supplied to |
|
20 | roots of the nodes that would be incoming, to be supplied to | |
21 | changegroupsubset. No code except for pull should be relying on this fact |
|
21 | changegroupsubset. No code except for pull should be relying on this fact | |
22 | any longer. |
|
22 | any longer. | |
23 | "heads" is either the supplied heads, or else the remote's heads. |
|
23 | "heads" is either the supplied heads, or else the remote's heads. | |
24 |
|
24 | |||
25 | If you pass heads and they are all known locally, the response lists just |
|
25 | If you pass heads and they are all known locally, the response lists just | |
26 | these heads in "common" and in "heads". |
|
26 | these heads in "common" and in "heads". | |
27 |
|
27 | |||
28 | Please use findcommonoutgoing to compute the set of outgoing nodes to give |
|
28 | Please use findcommonoutgoing to compute the set of outgoing nodes to give | |
29 | extensions a good hook into outgoing. |
|
29 | extensions a good hook into outgoing. | |
30 | """ |
|
30 | """ | |
31 |
|
31 | |||
32 | if not remote.capable('getbundle'): |
|
32 | if not remote.capable('getbundle'): | |
33 | return treediscovery.findcommonincoming(repo, remote, heads, force) |
|
33 | return treediscovery.findcommonincoming(repo, remote, heads, force) | |
34 |
|
34 | |||
35 | if heads: |
|
35 | if heads: | |
36 | allknown = True |
|
36 | allknown = True | |
37 | nm = repo.changelog.nodemap |
|
37 | nm = repo.changelog.nodemap | |
38 | for h in heads: |
|
38 | for h in heads: | |
39 | if nm.get(h) is None: |
|
39 | if nm.get(h) is None: | |
40 | allknown = False |
|
40 | allknown = False | |
41 | break |
|
41 | break | |
42 | if allknown: |
|
42 | if allknown: | |
43 | return (heads, False, heads) |
|
43 | return (heads, False, heads) | |
44 |
|
44 | |||
45 | res = setdiscovery.findcommonheads(repo.ui, repo, remote, |
|
45 | res = setdiscovery.findcommonheads(repo.ui, repo, remote, | |
46 | abortwhenunrelated=not force) |
|
46 | abortwhenunrelated=not force) | |
47 | common, anyinc, srvheads = res |
|
47 | common, anyinc, srvheads = res | |
48 | return (list(common), anyinc, heads or list(srvheads)) |
|
48 | return (list(common), anyinc, heads or list(srvheads)) | |
49 |
|
49 | |||
50 | class outgoing(object): |
|
50 | class outgoing(object): | |
51 | '''Represents the set of nodes present in a local repo but not in a |
|
51 | '''Represents the set of nodes present in a local repo but not in a | |
52 | (possibly) remote one. |
|
52 | (possibly) remote one. | |
53 |
|
53 | |||
54 | Members: |
|
54 | Members: | |
55 |
|
55 | |||
56 | missing is a list of all nodes present in local but not in remote. |
|
56 | missing is a list of all nodes present in local but not in remote. | |
57 | common is a list of all nodes shared between the two repos. |
|
57 | common is a list of all nodes shared between the two repos. | |
58 | excluded is the list of missing changeset that shouldn't be sent remotely. |
|
58 | excluded is the list of missing changeset that shouldn't be sent remotely. | |
59 | missingheads is the list of heads of missing. |
|
59 | missingheads is the list of heads of missing. | |
60 | commonheads is the list of heads of common. |
|
60 | commonheads is the list of heads of common. | |
61 |
|
61 | |||
62 | The sets are computed on demand from the heads, unless provided upfront |
|
62 | The sets are computed on demand from the heads, unless provided upfront | |
63 | by discovery.''' |
|
63 | by discovery.''' | |
64 |
|
64 | |||
65 | def __init__(self, revlog, commonheads, missingheads): |
|
65 | def __init__(self, revlog, commonheads, missingheads): | |
66 | self.commonheads = commonheads |
|
66 | self.commonheads = commonheads | |
67 | self.missingheads = missingheads |
|
67 | self.missingheads = missingheads | |
68 | self._revlog = revlog |
|
68 | self._revlog = revlog | |
69 | self._common = None |
|
69 | self._common = None | |
70 | self._missing = None |
|
70 | self._missing = None | |
71 | self.excluded = [] |
|
71 | self.excluded = [] | |
72 |
|
72 | |||
73 | def _computecommonmissing(self): |
|
73 | def _computecommonmissing(self): | |
74 | sets = self._revlog.findcommonmissing(self.commonheads, |
|
74 | sets = self._revlog.findcommonmissing(self.commonheads, | |
75 | self.missingheads) |
|
75 | self.missingheads) | |
76 | self._common, self._missing = sets |
|
76 | self._common, self._missing = sets | |
77 |
|
77 | |||
78 | @util.propertycache |
|
78 | @util.propertycache | |
79 | def common(self): |
|
79 | def common(self): | |
80 | if self._common is None: |
|
80 | if self._common is None: | |
81 | self._computecommonmissing() |
|
81 | self._computecommonmissing() | |
82 | return self._common |
|
82 | return self._common | |
83 |
|
83 | |||
84 | @util.propertycache |
|
84 | @util.propertycache | |
85 | def missing(self): |
|
85 | def missing(self): | |
86 | if self._missing is None: |
|
86 | if self._missing is None: | |
87 | self._computecommonmissing() |
|
87 | self._computecommonmissing() | |
88 | return self._missing |
|
88 | return self._missing | |
89 |
|
89 | |||
90 | def findcommonoutgoing(repo, other, onlyheads=None, force=False, |
|
90 | def findcommonoutgoing(repo, other, onlyheads=None, force=False, | |
91 | commoninc=None, portable=False): |
|
91 | commoninc=None, portable=False): | |
92 | '''Return an outgoing instance to identify the nodes present in repo but |
|
92 | '''Return an outgoing instance to identify the nodes present in repo but | |
93 | not in other. |
|
93 | not in other. | |
94 |
|
94 | |||
95 | If onlyheads is given, only nodes ancestral to nodes in onlyheads |
|
95 | If onlyheads is given, only nodes ancestral to nodes in onlyheads | |
96 | (inclusive) are included. If you already know the local repo's heads, |
|
96 | (inclusive) are included. If you already know the local repo's heads, | |
97 | passing them in onlyheads is faster than letting them be recomputed here. |
|
97 | passing them in onlyheads is faster than letting them be recomputed here. | |
98 |
|
98 | |||
99 | If commoninc is given, it must be the result of a prior call to |
|
99 | If commoninc is given, it must be the result of a prior call to | |
100 | findcommonincoming(repo, other, force) to avoid recomputing it here. |
|
100 | findcommonincoming(repo, other, force) to avoid recomputing it here. | |
101 |
|
101 | |||
102 | If portable is given, compute more conservative common and missingheads, |
|
102 | If portable is given, compute more conservative common and missingheads, | |
103 | to make bundles created from the instance more portable.''' |
|
103 | to make bundles created from the instance more portable.''' | |
104 | # declare an empty outgoing object to be filled later |
|
104 | # declare an empty outgoing object to be filled later | |
105 | og = outgoing(repo.changelog, None, None) |
|
105 | og = outgoing(repo.changelog, None, None) | |
106 |
|
106 | |||
107 | # get common set if not provided |
|
107 | # get common set if not provided | |
108 | if commoninc is None: |
|
108 | if commoninc is None: | |
109 | commoninc = findcommonincoming(repo, other, force=force) |
|
109 | commoninc = findcommonincoming(repo, other, force=force) | |
110 | og.commonheads, _any, _hds = commoninc |
|
110 | og.commonheads, _any, _hds = commoninc | |
111 |
|
111 | |||
112 | # compute outgoing |
|
112 | # compute outgoing | |
113 | mayexclude = (repo._phasecache.phaseroots[phases.secret] or repo.obsstore) |
|
113 | mayexclude = (repo._phasecache.phaseroots[phases.secret] or repo.obsstore) | |
114 | if not mayexclude: |
|
114 | if not mayexclude: | |
115 | og.missingheads = onlyheads or repo.heads() |
|
115 | og.missingheads = onlyheads or repo.heads() | |
116 | elif onlyheads is None: |
|
116 | elif onlyheads is None: | |
117 | # use visible heads as it should be cached |
|
117 | # use visible heads as it should be cached | |
118 | og.missingheads = visibleheads(repo) |
|
118 | og.missingheads = visibleheads(repo) | |
119 | og.excluded = [ctx.node() for ctx in repo.set('secret() or extinct()')] |
|
119 | og.excluded = [ctx.node() for ctx in repo.set('secret() or extinct()')] | |
120 | else: |
|
120 | else: | |
121 | # compute common, missing and exclude secret stuff |
|
121 | # compute common, missing and exclude secret stuff | |
122 | sets = repo.changelog.findcommonmissing(og.commonheads, onlyheads) |
|
122 | sets = repo.changelog.findcommonmissing(og.commonheads, onlyheads) | |
123 | og._common, allmissing = sets |
|
123 | og._common, allmissing = sets | |
124 | og._missing = missing = [] |
|
124 | og._missing = missing = [] | |
125 | og.excluded = excluded = [] |
|
125 | og.excluded = excluded = [] | |
126 | for node in allmissing: |
|
126 | for node in allmissing: | |
127 | ctx = repo[node] |
|
127 | ctx = repo[node] | |
128 | if ctx.phase() >= phases.secret or ctx.extinct(): |
|
128 | if ctx.phase() >= phases.secret or ctx.extinct(): | |
129 | excluded.append(node) |
|
129 | excluded.append(node) | |
130 | else: |
|
130 | else: | |
131 | missing.append(node) |
|
131 | missing.append(node) | |
132 | if len(missing) == len(allmissing): |
|
132 | if len(missing) == len(allmissing): | |
133 | missingheads = onlyheads |
|
133 | missingheads = onlyheads | |
134 | else: # update missing heads |
|
134 | else: # update missing heads | |
135 | missingheads = phases.newheads(repo, onlyheads, excluded) |
|
135 | missingheads = phases.newheads(repo, onlyheads, excluded) | |
136 | og.missingheads = missingheads |
|
136 | og.missingheads = missingheads | |
137 | if portable: |
|
137 | if portable: | |
138 | # recompute common and missingheads as if -r<rev> had been given for |
|
138 | # recompute common and missingheads as if -r<rev> had been given for | |
139 | # each head of missing, and --base <rev> for each head of the proper |
|
139 | # each head of missing, and --base <rev> for each head of the proper | |
140 | # ancestors of missing |
|
140 | # ancestors of missing | |
141 | og._computecommonmissing() |
|
141 | og._computecommonmissing() | |
142 | cl = repo.changelog |
|
142 | cl = repo.changelog | |
143 | missingrevs = set(cl.rev(n) for n in og._missing) |
|
143 | missingrevs = set(cl.rev(n) for n in og._missing) | |
144 | og._common = set(cl.ancestors(missingrevs)) - missingrevs |
|
144 | og._common = set(cl.ancestors(missingrevs)) - missingrevs | |
145 | commonheads = set(og.commonheads) |
|
145 | commonheads = set(og.commonheads) | |
146 | og.missingheads = [h for h in og.missingheads if h not in commonheads] |
|
146 | og.missingheads = [h for h in og.missingheads if h not in commonheads] | |
147 |
|
147 | |||
148 | return og |
|
148 | return og | |
149 |
|
149 | |||
150 | def _headssummary(repo, remote, outgoing): |
|
150 | def _headssummary(repo, remote, outgoing): | |
151 | """compute a summary of branch and heads status before and after push |
|
151 | """compute a summary of branch and heads status before and after push | |
152 |
|
152 | |||
153 | return {'branch': ([remoteheads], [newheads], [unsyncedheads])} mapping |
|
153 | return {'branch': ([remoteheads], [newheads], [unsyncedheads])} mapping | |
154 |
|
154 | |||
155 | - branch: the branch name |
|
155 | - branch: the branch name | |
156 | - remoteheads: the list of remote heads known locally |
|
156 | - remoteheads: the list of remote heads known locally | |
157 | None is the branch is new |
|
157 | None is the branch is new | |
158 | - newheads: the new remote heads (known locally) with outgoing pushed |
|
158 | - newheads: the new remote heads (known locally) with outgoing pushed | |
159 | - unsyncedheads: the list of remote heads unknown locally. |
|
159 | - unsyncedheads: the list of remote heads unknown locally. | |
160 | """ |
|
160 | """ | |
161 | cl = repo.changelog |
|
161 | cl = repo.changelog | |
162 | headssum = {} |
|
162 | headssum = {} | |
163 | # A. Create set of branches involved in the push. |
|
163 | # A. Create set of branches involved in the push. | |
164 | branches = set(repo[n].branch() for n in outgoing.missing) |
|
164 | branches = set(repo[n].branch() for n in outgoing.missing) | |
165 | remotemap = remote.branchmap() |
|
165 | remotemap = remote.branchmap() | |
166 | newbranches = branches - set(remotemap) |
|
166 | newbranches = branches - set(remotemap) | |
167 | branches.difference_update(newbranches) |
|
167 | branches.difference_update(newbranches) | |
168 |
|
168 | |||
169 | # A. register remote heads |
|
169 | # A. register remote heads | |
170 | remotebranches = set() |
|
170 | remotebranches = set() | |
171 | for branch, heads in remote.branchmap().iteritems(): |
|
171 | for branch, heads in remote.branchmap().iteritems(): | |
172 | remotebranches.add(branch) |
|
172 | remotebranches.add(branch) | |
173 | known = [] |
|
173 | known = [] | |
174 | unsynced = [] |
|
174 | unsynced = [] | |
175 | for h in heads: |
|
175 | for h in heads: | |
176 | if h in cl.nodemap: |
|
176 | if h in cl.nodemap: | |
177 | known.append(h) |
|
177 | known.append(h) | |
178 | else: |
|
178 | else: | |
179 | unsynced.append(h) |
|
179 | unsynced.append(h) | |
180 | headssum[branch] = (known, list(known), unsynced) |
|
180 | headssum[branch] = (known, list(known), unsynced) | |
181 | # B. add new branch data |
|
181 | # B. add new branch data | |
182 | missingctx = list(repo[n] for n in outgoing.missing) |
|
182 | missingctx = list(repo[n] for n in outgoing.missing) | |
183 | touchedbranches = set() |
|
183 | touchedbranches = set() | |
184 | for ctx in missingctx: |
|
184 | for ctx in missingctx: | |
185 | branch = ctx.branch() |
|
185 | branch = ctx.branch() | |
186 | touchedbranches.add(branch) |
|
186 | touchedbranches.add(branch) | |
187 | if branch not in headssum: |
|
187 | if branch not in headssum: | |
188 | headssum[branch] = (None, [], []) |
|
188 | headssum[branch] = (None, [], []) | |
189 |
|
189 | |||
190 | # C drop data about untouched branches: |
|
190 | # C drop data about untouched branches: | |
191 | for branch in remotebranches - touchedbranches: |
|
191 | for branch in remotebranches - touchedbranches: | |
192 | del headssum[branch] |
|
192 | del headssum[branch] | |
193 |
|
193 | |||
194 | # D. Update newmap with outgoing changes. |
|
194 | # D. Update newmap with outgoing changes. | |
195 | # This will possibly add new heads and remove existing ones. |
|
195 | # This will possibly add new heads and remove existing ones. | |
196 | newmap = branchmap.branchcache((branch, heads[1]) |
|
196 | newmap = branchmap.branchcache((branch, heads[1]) | |
197 | for branch, heads in headssum.iteritems() |
|
197 | for branch, heads in headssum.iteritems() | |
198 | if heads[0] is not None) |
|
198 | if heads[0] is not None) | |
199 | newmap.update(repo, missingctx) |
|
199 | newmap.update(repo, missingctx) | |
200 | for branch, newheads in newmap.iteritems(): |
|
200 | for branch, newheads in newmap.iteritems(): | |
201 | headssum[branch][1][:] = newheads |
|
201 | headssum[branch][1][:] = newheads | |
202 | return headssum |
|
202 | return headssum | |
203 |
|
203 | |||
204 | def _oldheadssummary(repo, remoteheads, outgoing, inc=False): |
|
204 | def _oldheadssummary(repo, remoteheads, outgoing, inc=False): | |
205 | """Compute branchmapsummary for repo without branchmap support""" |
|
205 | """Compute branchmapsummary for repo without branchmap support""" | |
206 |
|
206 | |||
207 | cl = repo.changelog |
|
207 | cl = repo.changelog | |
208 | # 1-4b. old servers: Check for new topological heads. |
|
208 | # 1-4b. old servers: Check for new topological heads. | |
209 | # Construct {old,new}map with branch = None (topological branch). |
|
209 | # Construct {old,new}map with branch = None (topological branch). | |
210 | # (code based on update) |
|
210 | # (code based on update) | |
211 | oldheads = set(h for h in remoteheads if h in cl.nodemap) |
|
211 | oldheads = set(h for h in remoteheads if h in cl.nodemap) | |
212 | # all nodes in outgoing.missing are children of either: |
|
212 | # all nodes in outgoing.missing are children of either: | |
213 | # - an element of oldheads |
|
213 | # - an element of oldheads | |
214 | # - another element of outgoing.missing |
|
214 | # - another element of outgoing.missing | |
215 | # - nullrev |
|
215 | # - nullrev | |
216 | # This explains why the new head are very simple to compute. |
|
216 | # This explains why the new head are very simple to compute. | |
217 | r = repo.set('heads(%ln + %ln)', oldheads, outgoing.missing) |
|
217 | r = repo.set('heads(%ln + %ln)', oldheads, outgoing.missing) | |
218 | newheads = list(c.node() for c in r) |
|
218 | newheads = list(c.node() for c in r) | |
219 | unsynced = inc and set([None]) or set() |
|
219 | unsynced = inc and set([None]) or set() | |
220 | return {None: (oldheads, newheads, unsynced)} |
|
220 | return {None: (oldheads, newheads, unsynced)} | |
221 |
|
221 | |||
222 | def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False): |
|
222 | def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False): | |
223 | """Check that a push won't add any outgoing head |
|
223 | """Check that a push won't add any outgoing head | |
224 |
|
224 | |||
225 | raise Abort error and display ui message as needed. |
|
225 | raise Abort error and display ui message as needed. | |
226 | """ |
|
226 | """ | |
227 | # Check for each named branch if we're creating new remote heads. |
|
227 | # Check for each named branch if we're creating new remote heads. | |
228 | # To be a remote head after push, node must be either: |
|
228 | # To be a remote head after push, node must be either: | |
229 | # - unknown locally |
|
229 | # - unknown locally | |
230 | # - a local outgoing head descended from update |
|
230 | # - a local outgoing head descended from update | |
231 | # - a remote head that's known locally and not |
|
231 | # - a remote head that's known locally and not | |
232 | # ancestral to an outgoing head |
|
232 | # ancestral to an outgoing head | |
233 | if remoteheads == [nullid]: |
|
233 | if remoteheads == [nullid]: | |
234 | # remote is empty, nothing to check. |
|
234 | # remote is empty, nothing to check. | |
235 | return |
|
235 | return | |
236 |
|
236 | |||
237 | if remote.capable('branchmap'): |
|
237 | if remote.capable('branchmap'): | |
238 | headssum = _headssummary(repo, remote, outgoing) |
|
238 | headssum = _headssummary(repo, remote, outgoing) | |
239 | else: |
|
239 | else: | |
240 | headssum = _oldheadssummary(repo, remoteheads, outgoing, inc) |
|
240 | headssum = _oldheadssummary(repo, remoteheads, outgoing, inc) | |
241 | newbranches = [branch for branch, heads in headssum.iteritems() |
|
241 | newbranches = [branch for branch, heads in headssum.iteritems() | |
242 | if heads[0] is None] |
|
242 | if heads[0] is None] | |
243 | # 1. Check for new branches on the remote. |
|
243 | # 1. Check for new branches on the remote. | |
244 | if newbranches and not newbranch: # new branch requires --new-branch |
|
244 | if newbranches and not newbranch: # new branch requires --new-branch | |
245 | branchnames = ', '.join(sorted(newbranches)) |
|
245 | branchnames = ', '.join(sorted(newbranches)) | |
246 | raise util.Abort(_("push creates new remote branches: %s!") |
|
246 | raise util.Abort(_("push creates new remote branches: %s!") | |
247 | % branchnames, |
|
247 | % branchnames, | |
248 | hint=_("use 'hg push --new-branch' to create" |
|
248 | hint=_("use 'hg push --new-branch' to create" | |
249 | " new remote branches")) |
|
249 | " new remote branches")) | |
250 |
|
250 | |||
251 | # 2 compute newly pushed bookmarks. We |
|
251 | # 2 compute newly pushed bookmarks. We | |
252 | # we don't warned about bookmarked heads. |
|
252 | # we don't warned about bookmarked heads. | |
253 | localbookmarks = repo._bookmarks |
|
253 | localbookmarks = repo._bookmarks | |
254 | remotebookmarks = remote.listkeys('bookmarks') |
|
254 | remotebookmarks = remote.listkeys('bookmarks') | |
255 | bookmarkedheads = set() |
|
255 | bookmarkedheads = set() | |
256 | for bm in localbookmarks: |
|
256 | for bm in localbookmarks: | |
257 | rnode = remotebookmarks.get(bm) |
|
257 | rnode = remotebookmarks.get(bm) | |
258 | if rnode and rnode in repo: |
|
258 | if rnode and rnode in repo: | |
259 | lctx, rctx = repo[bm], repo[rnode] |
|
259 | lctx, rctx = repo[bm], repo[rnode] | |
260 | if bookmarks.validdest(repo, rctx, lctx): |
|
260 | if bookmarks.validdest(repo, rctx, lctx): | |
261 | bookmarkedheads.add(lctx.node()) |
|
261 | bookmarkedheads.add(lctx.node()) | |
262 |
|
262 | |||
263 | # 3. Check for new heads. |
|
263 | # 3. Check for new heads. | |
264 | # If there are more heads after the push than before, a suitable |
|
264 | # If there are more heads after the push than before, a suitable | |
265 | # error message, depending on unsynced status, is displayed. |
|
265 | # error message, depending on unsynced status, is displayed. | |
266 | error = None |
|
266 | error = None | |
267 | unsynced = False |
|
267 | unsynced = False | |
268 | allmissing = set(outgoing.missing) |
|
268 | allmissing = set(outgoing.missing) | |
269 | allfuturecommon = set(c.node() for c in repo.set('%ld', outgoing.common)) |
|
269 | allfuturecommon = set(c.node() for c in repo.set('%ld', outgoing.common)) | |
270 | allfuturecommon.update(allmissing) |
|
270 | allfuturecommon.update(allmissing) | |
271 | for branch, heads in headssum.iteritems(): |
|
271 | for branch, heads in headssum.iteritems(): | |
272 | if heads[0] is None: |
|
272 | if heads[0] is None: | |
273 | # Maybe we should abort if we push more that one head |
|
273 | # Maybe we should abort if we push more that one head | |
274 | # for new branches ? |
|
274 | # for new branches ? | |
275 | continue |
|
275 | continue | |
276 | candidate_newhs = set(heads[1]) |
|
276 | candidate_newhs = set(heads[1]) | |
277 | # add unsynced data |
|
277 | # add unsynced data | |
278 | oldhs = set(heads[0]) |
|
278 | oldhs = set(heads[0]) | |
279 | oldhs.update(heads[2]) |
|
279 | oldhs.update(heads[2]) | |
280 | candidate_newhs.update(heads[2]) |
|
280 | candidate_newhs.update(heads[2]) | |
281 | dhs = None |
|
281 | dhs = None | |
282 | discardedheads = set() |
|
282 | discardedheads = set() | |
283 | if repo.obsstore: |
|
283 | if repo.obsstore: | |
284 | # remove future heads which are actually obsolete by another |
|
284 | # remove future heads which are actually obsolete by another | |
285 | # pushed element: |
|
285 | # pushed element: | |
286 | # |
|
286 | # | |
287 | # XXX as above, There are several cases this case does not handle |
|
287 | # XXX as above, There are several cases this case does not handle | |
288 | # XXX properly |
|
288 | # XXX properly | |
289 | # |
|
289 | # | |
290 | # (1) if <nh> is public, it won't be affected by obsolete marker |
|
290 | # (1) if <nh> is public, it won't be affected by obsolete marker | |
291 | # and a new is created |
|
291 | # and a new is created | |
292 | # |
|
292 | # | |
293 | # (2) if the new heads have ancestors which are not obsolete and |
|
293 | # (2) if the new heads have ancestors which are not obsolete and | |
294 | # not ancestors of any other heads we will have a new head too. |
|
294 | # not ancestors of any other heads we will have a new head too. | |
295 | # |
|
295 | # | |
296 | # This two case will be easy to handle for know changeset but much |
|
296 | # This two case will be easy to handle for know changeset but much | |
297 | # more tricky for unsynced changes. |
|
297 | # more tricky for unsynced changes. | |
298 | newhs = set() |
|
298 | newhs = set() | |
299 | for nh in candidate_newhs: |
|
299 | for nh in candidate_newhs: | |
300 | if nh in repo and repo[nh].phase() <= phases.public: |
|
300 | if nh in repo and repo[nh].phase() <= phases.public: | |
301 | newhs.add(nh) |
|
301 | newhs.add(nh) | |
302 | else: |
|
302 | else: | |
303 | for suc in obsolete.allsuccessors(repo.obsstore, [nh]): |
|
303 | for suc in obsolete.allsuccessors(repo.obsstore, [nh]): | |
304 | if suc != nh and suc in allfuturecommon: |
|
304 | if suc != nh and suc in allfuturecommon: | |
305 | discardedheads.add(nh) |
|
305 | discardedheads.add(nh) | |
306 | break |
|
306 | break | |
307 | else: |
|
307 | else: | |
308 | newhs.add(nh) |
|
308 | newhs.add(nh) | |
309 | else: |
|
309 | else: | |
310 | newhs = candidate_newhs |
|
310 | newhs = candidate_newhs | |
311 | if [h for h in heads[2] if h not in discardedheads]: |
|
311 | if [h for h in heads[2] if h not in discardedheads]: | |
312 | unsynced = True |
|
312 | unsynced = True | |
313 | if len(newhs) > len(oldhs): |
|
313 | if len(newhs) > len(oldhs): | |
314 | # strip updates to existing remote heads from the new heads list |
|
314 | # strip updates to existing remote heads from the new heads list | |
315 | dhs = list(newhs - bookmarkedheads - oldhs) |
|
315 | dhs = list(newhs - bookmarkedheads - oldhs) | |
316 | if dhs: |
|
316 | if dhs: | |
317 | if error is None: |
|
317 | if error is None: | |
318 | if branch not in ('default', None): |
|
318 | if branch not in ('default', None): | |
319 | error = _("push creates new remote head %s " |
|
319 | error = _("push creates new remote head %s " | |
320 | "on branch '%s'!") % (short(dhs[0]), branch) |
|
320 | "on branch '%s'!") % (short(dhs[0]), branch) | |
321 | else: |
|
321 | else: | |
322 | error = _("push creates new remote head %s!" |
|
322 | error = _("push creates new remote head %s!" | |
323 | ) % short(dhs[0]) |
|
323 | ) % short(dhs[0]) | |
324 | if heads[2]: # unsynced |
|
324 | if heads[2]: # unsynced | |
325 | hint = _("you should pull and merge or " |
|
325 | hint = _("you should pull and merge or " | |
326 | "use push -f to force") |
|
326 | "use push -f to force") | |
327 | else: |
|
327 | else: | |
328 | hint = _("did you forget to merge? " |
|
328 | hint = _("did you forget to merge? " | |
329 | "use push -f to force") |
|
329 | "use push -f to force") | |
330 | if branch is not None: |
|
330 | if branch is not None: | |
331 | repo.ui.note(_("new remote heads on branch '%s'\n") % branch) |
|
331 | repo.ui.note(_("new remote heads on branch '%s'\n") % branch) | |
332 | for h in dhs: |
|
332 | for h in dhs: | |
333 | repo.ui.note(_("new remote head %s\n") % short(h)) |
|
333 | repo.ui.note(_("new remote head %s\n") % short(h)) | |
334 | if error: |
|
334 | if error: | |
335 | raise util.Abort(error, hint=hint) |
|
335 | raise util.Abort(error, hint=hint) | |
336 |
|
336 | |||
337 | # 6. Check for unsynced changes on involved branches. |
|
337 | # 6. Check for unsynced changes on involved branches. | |
338 | if unsynced: |
|
338 | if unsynced: | |
339 | repo.ui.warn(_("note: unsynced remote changes!\n")) |
|
339 | repo.ui.warn(_("note: unsynced remote changes!\n")) | |
340 |
|
340 | |||
341 | def visibleheads(repo): |
|
341 | def visibleheads(repo): | |
342 | """return the set of visible head of this repo""" |
|
342 | """return the set of visible head of this repo""" | |
343 | return repo.filtered('unserved').heads() |
|
343 | return repo.filtered('unserved').heads() | |
344 |
|
||||
345 |
|
||||
346 | def visiblebranchmap(repo): |
|
|||
347 | """return a branchmap for the visible set""" |
|
|||
348 | return repo.filtered('unserved').branchmap() |
|
General Comments 0
You need to be logged in to leave comments.
Login now