Mercurial > hg
comparison mercurial/discovery.py @ 11578:bb7af1de5e38
discovery: remove duplication for new remote head discovery
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Thu, 15 Jul 2010 21:44:51 +0200 |
parents | 0bc450253312 |
children | 9c5794223340 |
comparison
equal
deleted
inserted
replaced
11577:0bc450253312 | 11578:bb7af1de5e38 |
---|---|
236 if not bases: | 236 if not bases: |
237 repo.ui.status(_("no changes found\n")) | 237 repo.ui.status(_("no changes found\n")) |
238 return None, 1 | 238 return None, 1 |
239 | 239 |
240 if not force and remoteheads != [nullid]: | 240 if not force and remoteheads != [nullid]: |
241 | |
242 def fail_multiple_heads(unsynced, branch=None): | |
243 if branch: | |
244 msg = _("push creates new remote heads " | |
245 "on branch '%s'!") % branch | |
246 else: | |
247 msg = _("push creates new remote heads!") | |
248 | |
249 if unsynced: | |
250 hint = _("you should pull and merge or use push -f to force") | |
251 else: | |
252 hint = _("did you forget to merge? use push -f to force") | |
253 raise util.Abort(msg, hint=hint) | |
254 | |
255 if remote.capable('branchmap'): | 241 if remote.capable('branchmap'): |
256 # Check for each named branch if we're creating new remote heads. | 242 # Check for each named branch if we're creating new remote heads. |
257 # To be a remote head after push, node must be either: | 243 # To be a remote head after push, node must be either: |
258 # - unknown locally | 244 # - unknown locally |
259 # - a local outgoing head descended from update | 245 # - a local outgoing head descended from update |
296 # 4. Update newmap with outgoing changes. | 282 # 4. Update newmap with outgoing changes. |
297 # This will possibly add new heads and remove existing ones. | 283 # This will possibly add new heads and remove existing ones. |
298 ctxgen = (repo[n] for n in outg) | 284 ctxgen = (repo[n] for n in outg) |
299 repo._updatebranchcache(newmap, ctxgen) | 285 repo._updatebranchcache(newmap, ctxgen) |
300 | 286 |
301 # 5. Check for new heads. | |
302 # If there are more heads after the push than before, a suitable | |
303 # warning, depending on unsynced status, is displayed. | |
304 for branch in branches: | |
305 if len(newmap[branch]) > len(oldmap[branch]): | |
306 return fail_multiple_heads(branch in unsynced, branch) | |
307 | |
308 # 6. Check for unsynced changes on involved branches. | |
309 if unsynced: | |
310 repo.ui.warn(_("note: unsynced remote changes!\n")) | |
311 | |
312 else: | 287 else: |
313 # Old servers: Check for new topological heads. | 288 # 1-4b. old servers: Check for new topological heads. |
314 # Code based on _updatebranchcache. | 289 # Construct {old,new}map with branch = None (topological branch). |
315 newheads = set(h for h in remoteheads if h in cl.nodemap) | 290 # (code based on _updatebranchcache) |
316 oldheadcnt = len(newheads) | 291 oldheads = set(h for h in remoteheads if h in cl.nodemap) |
317 newheads.update(outg) | 292 newheads = oldheads.union(outg) |
318 if len(newheads) > 1: | 293 if len(newheads) > 1: |
319 for latest in reversed(outg): | 294 for latest in reversed(outg): |
320 if latest not in newheads: | 295 if latest not in newheads: |
321 continue | 296 continue |
322 minhrev = min(cl.rev(h) for h in newheads) | 297 minhrev = min(cl.rev(h) for h in newheads) |
323 reachable = cl.reachable(latest, cl.node(minhrev)) | 298 reachable = cl.reachable(latest, cl.node(minhrev)) |
324 reachable.remove(latest) | 299 reachable.remove(latest) |
325 newheads.difference_update(reachable) | 300 newheads.difference_update(reachable) |
326 if len(newheads) > oldheadcnt: | 301 branches = set([None]) |
327 return fail_multiple_heads(inc) | 302 newmap = {None: newheads} |
328 if inc: | 303 oldmap = {None: oldheads} |
329 repo.ui.warn(_("note: unsynced remote changes!\n")) | 304 unsynced = inc and branches or set() |
305 | |
306 # 5. Check for new heads. | |
307 # If there are more heads after the push than before, a suitable | |
308 # warning, depending on unsynced status, is displayed. | |
309 for branch in branches: | |
310 if len(newmap[branch]) > len(oldmap[branch]): | |
311 if branch: | |
312 msg = _("push creates new remote heads " | |
313 "on branch '%s'!") % branch | |
314 else: | |
315 msg = _("push creates new remote heads!") | |
316 | |
317 if branch in unsynced: | |
318 hint = _("you should pull and merge or use push -f to force") | |
319 else: | |
320 hint = _("did you forget to merge? use push -f to force") | |
321 raise util.Abort(msg, hint=hint) | |
322 | |
323 # 6. Check for unsynced changes on involved branches. | |
324 if unsynced: | |
325 repo.ui.warn(_("note: unsynced remote changes!\n")) | |
330 | 326 |
331 if revs is None: | 327 if revs is None: |
332 # use the fast path, no race possible on push | 328 # use the fast path, no race possible on push |
333 nodes = repo.changelog.findmissing(common.keys()) | 329 nodes = repo.changelog.findmissing(common.keys()) |
334 cg = repo._changegroup(nodes, 'push') | 330 cg = repo._changegroup(nodes, 'push') |