mercurial/bundlerepo.py
changeset 14161 8a0fca925992
parent 14158 d8ba6fb2ce15
child 14190 8aab5a82685f
equal deleted inserted replaced
14160:a881a058823c 14161:8a0fca925992
   286             repopath, bundlename = s
   286             repopath, bundlename = s
   287     else:
   287     else:
   288         repopath, bundlename = parentpath, path
   288         repopath, bundlename = parentpath, path
   289     return bundlerepository(ui, repopath, bundlename)
   289     return bundlerepository(ui, repopath, bundlename)
   290 
   290 
   291 def getremotechanges(ui, repo, other, revs=None, bundlename=None,
   291 def getremotechanges(ui, repo, other, onlyheads=None, bundlename=None,
   292                      force=False):
   292                      force=False):
   293     tmp = discovery.findcommonincoming(repo, other, heads=revs, force=force)
   293     '''obtains a bundle of changes incoming from other
       
   294 
       
   295     "onlyheads" restricts the returned changes to those reachable from the
       
   296       specified heads.
       
   297     "bundlename", if given, stores the bundle to this file path permanently;
       
   298       the returned "bundle" will be None.
       
   299     "force" indicates whether to proceed on unrelated repos.
       
   300 
       
   301     Returns a tuple (local, csets, cleanupfn):
       
   302 
       
   303     "local" is a local repo from which to obtain the actual incoming changesets; it
       
   304       is a bundlerepo for the obtained bundle when the original "other" is remote.
       
   305     "csets" lists the incoming changeset node ids.
       
   306     "cleanupfn" must be called without arguments when you're done processing the
       
   307       changes; it closes both the original "other" and the one returned here.
       
   308     '''
       
   309     tmp = discovery.findcommonincoming(repo, other, heads=onlyheads, force=force)
   294     common, incoming, rheads = tmp
   310     common, incoming, rheads = tmp
   295     if not incoming:
   311     if not incoming:
   296         try:
   312         try:
   297             os.unlink(bundlename)
   313             os.unlink(bundlename)
   298         except OSError:
   314         except OSError:
   299             pass
   315             pass
   300         return other, None, None, None
   316         return other, [], other.close
   301 
   317 
   302     bundle = None
   318     bundle = None
       
   319     bundlerepo = None
       
   320     localrepo = other
   303     if bundlename or not other.local():
   321     if bundlename or not other.local():
   304         # create a bundle (uncompressed if other repo is not local)
   322         # create a bundle (uncompressed if other repo is not local)
   305 
   323 
   306         if revs is None and other.capable('changegroupsubset'):
   324         if onlyheads is None and other.capable('changegroupsubset'):
   307             revs = rheads
   325             onlyheads = rheads
   308 
   326 
   309         if other.capable('getbundle'):
   327         if other.capable('getbundle'):
   310             cg = other.getbundle('incoming', common=common, heads=revs)
   328             cg = other.getbundle('incoming', common=common, heads=onlyheads)
   311         elif revs is None:
   329         elif onlyheads is None:
   312             cg = other.changegroup(incoming, "incoming")
   330             cg = other.changegroup(incoming, "incoming")
   313         else:
   331         else:
   314             cg = other.changegroupsubset(incoming, revs, 'incoming')
   332             cg = other.changegroupsubset(incoming, onlyheads, 'incoming')
   315         bundletype = other.local() and "HG10BZ" or "HG10UN"
   333         bundletype = other.local() and "HG10BZ" or "HG10UN"
   316         fname = bundle = changegroup.writebundle(cg, bundlename, bundletype)
   334         fname = bundle = changegroup.writebundle(cg, bundlename, bundletype)
   317         # keep written bundle?
   335         # keep written bundle?
   318         if bundlename:
   336         if bundlename:
   319             bundle = None
   337             bundle = None
   320         if not other.local():
   338         if not other.local():
   321             # use the created uncompressed bundlerepo
   339             # use the created uncompressed bundlerepo
   322             other = bundlerepository(ui, repo.root, fname)
   340             localrepo = bundlerepo = bundlerepository(ui, repo.root, fname)
   323     return (other, common, incoming, bundle)
   341             # this repo contains local and other now, so filter out local again
   324 
   342             common = repo.heads()
       
   343 
       
   344     csets = localrepo.changelog.findmissing(common, onlyheads)
       
   345 
       
   346     def cleanup():
       
   347         if bundlerepo:
       
   348             bundlerepo.close()
       
   349         if bundle:
       
   350             os.unlink(bundle)
       
   351         localrepo.close()
       
   352 
       
   353     return (localrepo, csets, cleanup)
       
   354