Mercurial > public > mercurial-scm > hg-stable
diff mercurial/bundlerepo.py @ 12734:5dfd1c49dcc5
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.
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 22:41:43 +0200 |
parents | 6277a9469dff |
children | ad63e5f834e1 |
line wrap: on
line diff
--- 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) +