bundlerepo: unify common code into a new getremotechanges
The pattern where we fetch incoming remote changes and return
them as a local bundlerepo seems common. It's nicer to have this
code unified.
--- a/hgext/transplant.py Tue Oct 12 23:33:43 2010 -0500
+++ b/hgext/transplant.py Thu Oct 14 22:41:43 2010 +0200
@@ -15,8 +15,8 @@
from mercurial.i18n import _
import os, tempfile
-from mercurial import bundlerepo, changegroup, cmdutil, hg, merge, match
-from mercurial import patch, revlog, util, error, discovery
+from mercurial import bundlerepo, cmdutil, hg, merge, match
+from mercurial import patch, revlog, util, error
from mercurial import revset, help
class transplantentry(object):
@@ -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 = bundlerepo.getremotechanges(ui, repo, source,
+ force=True)
else:
source = repo
--- a/mercurial/bundlerepo.py Tue Oct 12 23:33:43 2010 -0500
+++ b/mercurial/bundlerepo.py Thu Oct 14 22:41:43 2010 +0200
@@ -14,7 +14,7 @@
from node import nullid
from i18n import _
import os, struct, tempfile, shutil
-import changegroup, util, mdiff
+import changegroup, util, mdiff, discovery
import localrepo, changelog, manifest, filelog, revlog, error
class bundlerevlog(revlog.revlog):
@@ -288,3 +288,35 @@
else:
repopath, bundlename = parentpath, path
return bundlerepository(ui, repopath, bundlename)
+
+def getremotechanges(ui, repo, other, revs=None, bundlename=None, force=False):
+ tmp = discovery.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
+ other = bundlerepository(ui, repo.root, fname)
+ return (other, incoming, bundle)
+
--- a/mercurial/hg.py Tue Oct 12 23:33:43 2010 -0500
+++ b/mercurial/hg.py Thu Oct 14 22:41:43 2010 +0200
@@ -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
@@ -423,38 +423,12 @@
if revs:
revs = [other.lookup(rev) for rev in revs]
- bundlename = opts["bundle"]
- force = opts["force"]
- tmp = discovery.findcommonincoming(repo, other, heads=revs, force=force)
- common, incoming, rheads = tmp
- if not incoming:
- try:
- os.unlink(bundlename)
- except:
- pass
+ other, incoming, bundle = bundlerepo.getremotechanges(ui, repo, other, revs,
+ opts["bundle"], opts["force"])
+ if incoming is None:
ui.status(_("no changes found\n"))
return subreporecurse()
- 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
- other = bundlerepo.bundlerepository(ui, repo.root, fname)
-
try:
chlist = other.changelog.nodesbetween(incoming, revs)[0]
displayer = cmdutil.show_changeset(ui, other, opts, buffered)