mercurial/changegroup.py
changeset 32150 282b288aa20c
parent 31608 4baf79a77afa
child 32164 29e286fa4db0
equal deleted inserted replaced
32149:9a9d54ae9963 32150:282b288aa20c
   500         return readexactly(self._fh, n)
   500         return readexactly(self._fh, n)
   501 
   501 
   502 class cg1packer(object):
   502 class cg1packer(object):
   503     deltaheader = _CHANGEGROUPV1_DELTA_HEADER
   503     deltaheader = _CHANGEGROUPV1_DELTA_HEADER
   504     version = '01'
   504     version = '01'
   505     def __init__(self, repo, bundlecaps=None):
   505     def __init__(self, repo):
   506         """Given a source repo, construct a bundler.
   506         """Given a source repo, construct a bundler.
   507 
       
   508         bundlecaps is optional and can be used to specify the set of
       
   509         capabilities which can be used to build the bundle.
       
   510         """
   507         """
   511         # Set of capabilities we can use to build the bundle.
       
   512         if bundlecaps is None:
       
   513             bundlecaps = set()
       
   514         self._bundlecaps = bundlecaps
       
   515         # experimental config: bundle.reorder
   508         # experimental config: bundle.reorder
   516         reorder = repo.ui.config('bundle', 'reorder', 'auto')
   509         reorder = repo.ui.config('bundle', 'reorder', 'auto')
   517         if reorder == 'auto':
   510         if reorder == 'auto':
   518             reorder = None
   511             reorder = None
   519         else:
   512         else:
   813 
   806 
   814 class cg2packer(cg1packer):
   807 class cg2packer(cg1packer):
   815     version = '02'
   808     version = '02'
   816     deltaheader = _CHANGEGROUPV2_DELTA_HEADER
   809     deltaheader = _CHANGEGROUPV2_DELTA_HEADER
   817 
   810 
   818     def __init__(self, repo, bundlecaps=None):
   811     def __init__(self, repo):
   819         super(cg2packer, self).__init__(repo, bundlecaps)
   812         super(cg2packer, self).__init__(repo)
   820         if self._reorder is None:
   813         if self._reorder is None:
   821             # Since generaldelta is directly supported by cg2, reordering
   814             # Since generaldelta is directly supported by cg2, reordering
   822             # generally doesn't help, so we disable it by default (treating
   815             # generally doesn't help, so we disable it by default (treating
   823             # bundle.reorder=auto just like bundle.reorder=False).
   816             # bundle.reorder=auto just like bundle.reorder=False).
   824             self._reorder = False
   817             self._reorder = False
   908     if 'generaldelta' in repo.requirements:
   901     if 'generaldelta' in repo.requirements:
   909         versions.discard('01')
   902         versions.discard('01')
   910     assert versions
   903     assert versions
   911     return min(versions)
   904     return min(versions)
   912 
   905 
   913 def getbundler(version, repo, bundlecaps=None):
   906 def getbundler(version, repo):
   914     assert version in supportedoutgoingversions(repo)
   907     assert version in supportedoutgoingversions(repo)
   915     return _packermap[version][0](repo, bundlecaps)
   908     return _packermap[version][0](repo)
   916 
   909 
   917 def getunbundler(version, fh, alg, extras=None):
   910 def getunbundler(version, fh, alg, extras=None):
   918     return _packermap[version][1](fh, alg, extras=extras)
   911     return _packermap[version][1](fh, alg, extras=extras)
   919 
   912 
   920 def _changegroupinfo(repo, nodes, source):
   913 def _changegroupinfo(repo, nodes, source):
   961     """
   954     """
   962     outgoing = discovery.outgoing(repo, missingroots=roots, missingheads=heads)
   955     outgoing = discovery.outgoing(repo, missingroots=roots, missingheads=heads)
   963     bundler = getbundler(version, repo)
   956     bundler = getbundler(version, repo)
   964     return getsubset(repo, outgoing, bundler, source)
   957     return getsubset(repo, outgoing, bundler, source)
   965 
   958 
   966 def getlocalchangegroupraw(repo, source, outgoing, bundlecaps=None,
   959 def getlocalchangegroupraw(repo, source, outgoing, version='01'):
   967                            version='01'):
       
   968     """Like getbundle, but taking a discovery.outgoing as an argument.
   960     """Like getbundle, but taking a discovery.outgoing as an argument.
   969 
   961 
   970     This is only implemented for local repos and reuses potentially
   962     This is only implemented for local repos and reuses potentially
   971     precomputed sets in outgoing. Returns a raw changegroup generator."""
   963     precomputed sets in outgoing. Returns a raw changegroup generator."""
   972     if not outgoing.missing:
   964     if not outgoing.missing:
   973         return None
   965         return None
   974     bundler = getbundler(version, repo, bundlecaps)
   966     bundler = getbundler(version, repo)
   975     return getsubsetraw(repo, outgoing, bundler, source)
   967     return getsubsetraw(repo, outgoing, bundler, source)
   976 
   968 
   977 def getlocalchangegroup(repo, source, outgoing, bundlecaps=None,
   969 def getlocalchangegroup(repo, source, outgoing, version='01'):
   978                         version='01'):
       
   979     """Like getbundle, but taking a discovery.outgoing as an argument.
   970     """Like getbundle, but taking a discovery.outgoing as an argument.
   980 
   971 
   981     This is only implemented for local repos and reuses potentially
   972     This is only implemented for local repos and reuses potentially
   982     precomputed sets in outgoing."""
   973     precomputed sets in outgoing."""
   983     if not outgoing.missing:
   974     if not outgoing.missing:
   984         return None
   975         return None
   985     bundler = getbundler(version, repo, bundlecaps)
   976     bundler = getbundler(version, repo)
   986     return getsubset(repo, outgoing, bundler, source)
   977     return getsubset(repo, outgoing, bundler, source)
   987 
   978 
   988 def getchangegroup(repo, source, outgoing, bundlecaps=None,
   979 def getchangegroup(repo, source, outgoing, version='01'):
   989                    version='01'):
       
   990     """Like changegroupsubset, but returns the set difference between the
   980     """Like changegroupsubset, but returns the set difference between the
   991     ancestors of heads and the ancestors common.
   981     ancestors of heads and the ancestors common.
   992 
   982 
   993     If heads is None, use the local heads. If common is None, use [nullid].
   983     If heads is None, use the local heads. If common is None, use [nullid].
   994 
   984 
   995     The nodes in common might not all be known locally due to the way the
   985     The nodes in common might not all be known locally due to the way the
   996     current discovery protocol works.
   986     current discovery protocol works.
   997     """
   987     """
   998     return getlocalchangegroup(repo, source, outgoing, bundlecaps=bundlecaps,
   988     return getlocalchangegroup(repo, source, outgoing, version=version)
   999                                version=version)
       
  1000 
   989 
  1001 def changegroup(repo, basenodes, source):
   990 def changegroup(repo, basenodes, source):
  1002     # to avoid a race we use changegroupsubset() (issue1320)
   991     # to avoid a race we use changegroupsubset() (issue1320)
  1003     return changegroupsubset(repo, basenodes, repo.heads(), source)
   992     return changegroupsubset(repo, basenodes, repo.heads(), source)
  1004 
   993