Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 12730:33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 21:36:00 +0200 |
parents | 55f0648c7e2d |
children | 5dfd1c49dcc5 |
comparison
equal
deleted
inserted
replaced
12729:55f0648c7e2d | 12730:33e1fd2aeb3c |
---|---|
406 "or 'hg update -C .' to abandon\n")) | 406 "or 'hg update -C .' to abandon\n")) |
407 elif remind: | 407 elif remind: |
408 repo.ui.status(_("(branch merge, don't forget to commit)\n")) | 408 repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
409 return stats[3] > 0 | 409 return stats[3] > 0 |
410 | 410 |
411 def _incoming(displaychlist, subreporecurse, ui, repo, source, | |
412 opts, buffered=False): | |
413 """ | |
414 Helper for incoming / gincoming. | |
415 displaychlist gets called with | |
416 (remoterepo, incomingchangesetlist, displayer) parameters, | |
417 and is supposed to contain only code that can't be unified. | |
418 """ | |
419 source, branches = parseurl(ui.expandpath(source), opts.get('branch')) | |
420 other = repository(remoteui(repo, opts), source) | |
421 ui.status(_('comparing with %s\n') % url.hidepassword(source)) | |
422 revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev')) | |
423 | |
424 if revs: | |
425 revs = [other.lookup(rev) for rev in revs] | |
426 bundlename = opts["bundle"] | |
427 force = opts["force"] | |
428 tmp = discovery.findcommonincoming(repo, other, heads=revs, force=force) | |
429 common, incoming, rheads = tmp | |
430 if not incoming: | |
431 try: | |
432 os.unlink(bundlename) | |
433 except: | |
434 pass | |
435 ui.status(_("no changes found\n")) | |
436 return subreporecurse() | |
437 | |
438 bundle = None | |
439 if bundlename or not other.local(): | |
440 # create a bundle (uncompressed if other repo is not local) | |
441 | |
442 if revs is None and other.capable('changegroupsubset'): | |
443 revs = rheads | |
444 | |
445 if revs is None: | |
446 cg = other.changegroup(incoming, "incoming") | |
447 else: | |
448 cg = other.changegroupsubset(incoming, revs, 'incoming') | |
449 bundletype = other.local() and "HG10BZ" or "HG10UN" | |
450 fname = bundle = changegroup.writebundle(cg, bundlename, bundletype) | |
451 # keep written bundle? | |
452 if bundlename: | |
453 bundle = None | |
454 if not other.local(): | |
455 # use the created uncompressed bundlerepo | |
456 other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
457 | |
458 try: | |
459 chlist = other.changelog.nodesbetween(incoming, revs)[0] | |
460 displayer = cmdutil.show_changeset(ui, other, opts, buffered) | |
461 | |
462 # XXX once graphlog extension makes it into core, | |
463 # should be replaced by a if graph/else | |
464 displaychlist(other, chlist, displayer) | |
465 | |
466 displayer.close() | |
467 finally: | |
468 if hasattr(other, 'close'): | |
469 other.close() | |
470 if bundle: | |
471 os.unlink(bundle) | |
472 subreporecurse() | |
473 return 0 # exit code is zero since we found incoming changes | |
474 | |
411 def incoming(ui, repo, source, opts): | 475 def incoming(ui, repo, source, opts): |
412 def recurse(): | 476 def subreporecurse(): |
413 ret = 1 | 477 ret = 1 |
414 if opts.get('subrepos'): | 478 if opts.get('subrepos'): |
415 ctx = repo[None] | 479 ctx = repo[None] |
416 for subpath in sorted(ctx.substate): | 480 for subpath in sorted(ctx.substate): |
417 sub = ctx.sub(subpath) | 481 sub = ctx.sub(subpath) |
418 ret = min(ret, sub.incoming(ui, source, opts)) | 482 ret = min(ret, sub.incoming(ui, source, opts)) |
419 return ret | 483 return ret |
420 | 484 |
421 limit = cmdutil.loglimit(opts) | 485 def display(other, chlist, displayer): |
422 source, branches = parseurl(ui.expandpath(source), opts.get('branch')) | 486 limit = cmdutil.loglimit(opts) |
423 other = repository(remoteui(repo, opts), source) | |
424 ui.status(_('comparing with %s\n') % url.hidepassword(source)) | |
425 revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev')) | |
426 if revs: | |
427 revs = [other.lookup(rev) for rev in revs] | |
428 | |
429 tmp = discovery.findcommonincoming(repo, other, heads=revs, | |
430 force=opts.get('force')) | |
431 common, incoming, rheads = tmp | |
432 if not incoming: | |
433 try: | |
434 os.unlink(opts["bundle"]) | |
435 except: | |
436 pass | |
437 ui.status(_("no changes found\n")) | |
438 return recurse() | |
439 | |
440 cleanup = None | |
441 try: | |
442 fname = opts["bundle"] | |
443 if fname or not other.local(): | |
444 # create a bundle (uncompressed if other repo is not local) | |
445 | |
446 if revs is None and other.capable('changegroupsubset'): | |
447 revs = rheads | |
448 | |
449 if revs is None: | |
450 cg = other.changegroup(incoming, "incoming") | |
451 else: | |
452 cg = other.changegroupsubset(incoming, revs, 'incoming') | |
453 bundletype = other.local() and "HG10BZ" or "HG10UN" | |
454 fname = cleanup = changegroup.writebundle(cg, fname, bundletype) | |
455 # keep written bundle? | |
456 if opts["bundle"]: | |
457 cleanup = None | |
458 if not other.local(): | |
459 # use the created uncompressed bundlerepo | |
460 other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
461 | |
462 chlist = other.changelog.nodesbetween(incoming, revs)[0] | |
463 if opts.get('newest_first'): | 487 if opts.get('newest_first'): |
464 chlist.reverse() | 488 chlist.reverse() |
465 displayer = cmdutil.show_changeset(ui, other, opts) | |
466 count = 0 | 489 count = 0 |
467 for n in chlist: | 490 for n in chlist: |
468 if limit is not None and count >= limit: | 491 if limit is not None and count >= limit: |
469 break | 492 break |
470 parents = [p for p in other.changelog.parents(n) if p != nullid] | 493 parents = [p for p in other.changelog.parents(n) if p != nullid] |
471 if opts.get('no_merges') and len(parents) == 2: | 494 if opts.get('no_merges') and len(parents) == 2: |
472 continue | 495 continue |
473 count += 1 | 496 count += 1 |
474 displayer.show(other[n]) | 497 displayer.show(other[n]) |
475 displayer.close() | 498 return _incoming(display, subreporecurse, ui, repo, source, opts) |
476 finally: | |
477 if hasattr(other, 'close'): | |
478 other.close() | |
479 if cleanup: | |
480 os.unlink(cleanup) | |
481 recurse() | |
482 return 0 # exit code is zero since we found incoming changes | |
483 | 499 |
484 def outgoing(ui, repo, dest, opts): | 500 def outgoing(ui, repo, dest, opts): |
485 def recurse(): | 501 def recurse(): |
486 ret = 1 | 502 ret = 1 |
487 if opts.get('subrepos'): | 503 if opts.get('subrepos'): |