rendered paste body# HG changeset patch# User Nicolas Dumazet <nicdumz.commits@gmail.com># Date 1287083735 -7200# Node ID 4029d78b352a4ad668a75142fba06bdbb61d1dd8# Parent 80a3d1121c106fd972fa84423f55b2ce2e9407c9too much, needs a split.- unify incoming and gincoming so they use the same code- unify transplant, incoming, gincoming so they use discovery.getremotechangesAdditional issues, besides size and readability:- getremotechanges should be moved somewhere else. Maybe in bundle.py- circular import solved by an inline importdiff --git a/hgext/graphlog.py b/hgext/graphlog.py--- a/hgext/graphlog.py+++ b/hgext/graphlog.py@@ -307,54 +307,16 @@ Nodes printed as an @ character are parents of the working directory. """+ def subreporecurse():+ return 1 check_unsupported_flags(opts)- source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))- other = hg.repository(hg.remoteui(repo, opts), source)- revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))- ui.status(_('comparing with %s\n') % url.hidepassword(source))- if revs:- revs = [other.lookup(rev) for rev in revs]- incoming = discovery.findincoming(repo, other, heads=revs,- force=opts["force"])- if not incoming:- try:- os.unlink(opts["bundle"])- except:- pass- ui.status(_("no changes found\n"))- return-- cleanup = None- try:-- fname = opts["bundle"]- if fname or not other.local():- # create a bundle (uncompressed if other repo is not local)- if revs is None:- cg = other.changegroup(incoming, "incoming")- else:- cg = other.changegroupsubset(incoming, revs, 'incoming')- bundletype = other.local() and "HG10BZ" or "HG10UN"- fname = cleanup = changegroup.writebundle(cg, fname, bundletype)- # keep written bundle?- if opts["bundle"]:- cleanup = None- if not other.local():- # use the created uncompressed bundlerepo- other = bundlerepo.bundlerepository(ui, repo.root, fname)-- chlist = other.changelog.nodesbetween(incoming, revs)[0]+ def callback(other, chlist, displayer): revdag = graphrevs(other, chlist, opts)- displayer = show_changeset(ui, other, opts, buffered=True) showparents = [ctx.node() for ctx in repo[None].parents()] generate(ui, revdag, displayer, showparents, asciiedges) - finally:- if hasattr(other, 'close'):- other.close()- if cleanup:- os.unlink(cleanup)+ hg._incoming(callback, subreporecurse, ui, repo, source, opts, buffered=True) def uisetup(ui): '''Initialize the extension.'''diff --git a/hgext/transplant.py b/hgext/transplant.py--- a/hgext/transplant.py+++ b/hgext/transplant.py@@ -15,7 +15,7 @@ from mercurial.i18n import _ import os, tempfile-from mercurial import bundlerepo, changegroup, cmdutil, hg, merge, match+from mercurial import cmdutil, hg, merge, match from mercurial import patch, revlog, util, error, discovery from mercurial import revset, help @@ -484,25 +484,6 @@ and then resume where you left off by calling :hg:`transplant --continue/-c`. '''- def getremotechanges(repo, url):- sourcerepo = ui.expandpath(url)- source = hg.repository(ui, sourcerepo)- tmp = discovery.findcommonincoming(repo, source, force=True)- common, incoming, rheads = tmp- if not incoming:- return (source, None, None)-- bundle = None- if not source.local():- if source.capable('changegroupsubset'):- cg = source.changegroupsubset(incoming, rheads, 'incoming')- else:- cg = source.changegroup(incoming, 'incoming')- bundle = changegroup.writebundle(cg, None, 'HG10UN')- source = bundlerepo.bundlerepository(ui, repo.root, bundle)-- return (source, incoming, bundle)- def incwalk(repo, incoming, branches, match=util.always): if not branches: branches = None@@ -559,7 +540,10 @@ bundle = None source = opts.get('source') if source:- (source, incoming, bundle) = getremotechanges(repo, source)+ sourcerepo = ui.expandpath(source)+ source = hg.repository(ui, sourcerepo)+ source, incoming, bundle = discovery.getremotechanges(ui, repo, source,+ force=True) else: source = repo diff --git a/mercurial/discovery.py b/mercurial/discovery.py--- a/mercurial/discovery.py+++ b/mercurial/discovery.py@@ -7,8 +7,14 @@ from node import nullid, short from i18n import _-import util, error+import util, error, changegroup+import os +def newdiscovery():+ """+ common, heads+ """+ pass def findincoming(repo, remote, base=None, heads=None, force=False): """Return list of roots of the subsets of missing nodes from remote @@ -331,3 +337,36 @@ else: cg = repo.changegroupsubset(update, revs, 'push') return cg, remoteheads++def getremotechanges(ui, repo, other, revs=None, bundlename=None, force=False):+ tmp = findcommonincoming(repo, other, heads=revs, force=force)+ common, incoming, rheads = tmp+ if not incoming:+ try:+ os.unlink(bundlename)+ except:+ pass+ return other, None, None++ bundle = None+ if bundlename or not other.local():+ # create a bundle (uncompressed if other repo is not local)++ if revs is None and other.capable('changegroupsubset'):+ revs = rheads++ if revs is None:+ cg = other.changegroup(incoming, "incoming")+ else:+ cg = other.changegroupsubset(incoming, revs, 'incoming')+ bundletype = other.local() and "HG10BZ" or "HG10UN"+ fname = bundle = changegroup.writebundle(cg, bundlename, bundletype)+ # keep written bundle?+ if bundlename:+ bundle = None+ if not other.local():+ # use the created uncompressed bundlerepo+ import bundlerepo+ other = bundlerepo.bundlerepository(ui, repo.root, fname)+ return (other, incoming, bundle)+diff --git a/mercurial/hg.py b/mercurial/hg.py--- a/mercurial/hg.py+++ b/mercurial/hg.py@@ -11,7 +11,7 @@ from node import hex, nullid, nullrev, short import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo import lock, util, extensions, error, encoding, node-import cmdutil, discovery, url, changegroup+import cmdutil, discovery, url import merge as mergemod import verify as verifymod import errno, os, shutil@@ -408,8 +408,42 @@ repo.ui.status(_("(branch merge, don't forget to commit)\n")) return stats[3] > 0 +def _incoming(callback, subreporecurse, ui, repo, source, opts, buffered=False):+ """+ Helper for incoming / gincoming.+ callback gets called with (remoterepo, incomingchangesetlist, displayer)+ parameters.+ """+ source, branches = parseurl(ui.expandpath(source), opts.get('branch'))+ other = repository(remoteui(repo, opts), source)+ ui.status(_('comparing with %s\n') % url.hidepassword(source))+ revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev'))++ if revs:+ revs = [other.lookup(rev) for rev in revs]+ other, incoming, bundle = discovery.getremotechanges(ui, repo, other, revs,+ opts["bundle"], opts["force"])+ if incoming is None:+ ui.status(_("no changes found\n"))+ return subreporecurse()++ try:+ chlist = other.changelog.nodesbetween(incoming, revs)[0]+ displayer = cmdutil.show_changeset(ui, other, opts, buffered)++ callback(other, chlist, displayer)++ displayer.close()+ finally:+ if hasattr(other, 'close'):+ other.close()+ if bundle:+ os.unlink(bundle)+ subreporecurse()+ return 0 # exit code is zero since we found incoming changes+ def incoming(ui, repo, source, opts):- def recurse():+ def subreporecurse(): ret = 1 if opts.get('subrepos'): ctx = repo[None]@@ -418,53 +452,12 @@ ret = min(ret, sub.incoming(ui, source, opts)) return ret - limit = cmdutil.loglimit(opts)- source, branches = parseurl(ui.expandpath(source), opts.get('branch'))- other = repository(remoteui(repo, opts), source)- ui.status(_('comparing with %s\n') % url.hidepassword(source))- revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev'))- if revs:- revs = [other.lookup(rev) for rev in revs]-- tmp = discovery.findcommonincoming(repo, other, heads=revs,- force=opts.get('force'))- common, incoming, rheads = tmp- if not incoming:- try:- os.unlink(opts["bundle"])- except:- pass- ui.status(_("no changes found\n"))- return recurse()-- cleanup = None- try:- fname = opts["bundle"]- if fname or not other.local():- # create a bundle (uncompressed if other repo is not local)-- if revs is None and other.capable('changegroupsubset'):- revs = rheads-- if revs is None:- cg = other.changegroup(incoming, "incoming")- else:- cg = other.changegroupsubset(incoming, revs, 'incoming')- bundletype = other.local() and "HG10BZ" or "HG10UN"- fname = cleanup = changegroup.writebundle(cg, fname, bundletype)- # keep written bundle?- if opts["bundle"]:- cleanup = None- if not other.local():- # use the created uncompressed bundlerepo- other = bundlerepo.bundlerepository(ui, repo.root, fname)-- o = other.changelog.nodesbetween(incoming, revs)[0]+ def callback(other, chlist, displayer):+ limit = cmdutil.loglimit(opts) if opts.get('newest_first'):- o.reverse()- displayer = cmdutil.show_changeset(ui, other, opts)+ chlist.reverse() count = 0- for n in o:+ for n in chlist: if limit is not None and count >= limit: break parents = [p for p in other.changelog.parents(n) if p != nullid]@@ -472,14 +465,7 @@ continue count += 1 displayer.show(other[n])- displayer.close()- finally:- if hasattr(other, 'close'):- other.close()- if cleanup:- os.unlink(cleanup)- recurse()- return 0 # exit code is zero since we found incoming changes+ return _incoming(callback, subreporecurse, ui, repo, source, opts) def outgoing(ui, repo, dest, opts): def recurse():