Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 19204:e9c5b1c246dc
bundle-ng: move bundle generation to changegroup.py
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sun, 10 Feb 2013 16:03:20 +0100 |
parents | 627cd7842e5d |
children | 93635f69c93b |
comparison
equal
deleted
inserted
replaced
19203:627cd7842e5d | 19204:e9c5b1c246dc |
---|---|
2033 def _changegroupsubset(self, outgoing, bundler, source, | 2033 def _changegroupsubset(self, outgoing, bundler, source, |
2034 fastpath=False): | 2034 fastpath=False): |
2035 commonrevs = outgoing.common | 2035 commonrevs = outgoing.common |
2036 csets = outgoing.missing | 2036 csets = outgoing.missing |
2037 heads = outgoing.missingheads | 2037 heads = outgoing.missingheads |
2038 cl = bundler._changelog | |
2039 mf = bundler._manifest | |
2040 mfs = {} # needed manifests | |
2041 fnodes = {} # needed file nodes | |
2042 changedfiles = set() | |
2043 fstate = ['', {}] | |
2044 | |
2045 # We go through the fast path if we get told to, or if all (unfiltered | 2038 # We go through the fast path if we get told to, or if all (unfiltered |
2046 # heads have been requested (since we then know there all linkrevs will | 2039 # heads have been requested (since we then know there all linkrevs will |
2047 # be pulled by the client). | 2040 # be pulled by the client). |
2048 heads.sort() | 2041 heads.sort() |
2049 fastpathlinkrev = fastpath or ( | 2042 fastpathlinkrev = fastpath or ( |
2050 self.filtername is None and heads == sorted(self.heads())) | 2043 self.filtername is None and heads == sorted(self.heads())) |
2051 | 2044 |
2052 self.hook('preoutgoing', throw=True, source=source) | 2045 self.hook('preoutgoing', throw=True, source=source) |
2053 self.changegroupinfo(csets, source) | 2046 self.changegroupinfo(csets, source) |
2054 | 2047 gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source) |
2055 # filter any nodes that claim to be part of the known set | |
2056 def prune(revlog, missing): | |
2057 rr, rl = revlog.rev, revlog.linkrev | |
2058 return [n for n in missing | |
2059 if rl(rr(n)) not in commonrevs] | |
2060 | |
2061 progress = self.ui.progress | |
2062 _bundling = _('bundling') | |
2063 _changesets = _('changesets') | |
2064 _manifests = _('manifests') | |
2065 _files = _('files') | |
2066 | |
2067 def lookup(revlog, x): | |
2068 count = bundler.count | |
2069 if revlog == cl: | |
2070 c = cl.read(x) | |
2071 changedfiles.update(c[3]) | |
2072 mfs.setdefault(c[0], x) | |
2073 count[0] += 1 | |
2074 progress(_bundling, count[0], | |
2075 unit=_changesets, total=count[1]) | |
2076 return x | |
2077 elif revlog == mf: | |
2078 clnode = mfs[x] | |
2079 if not fastpathlinkrev: | |
2080 mdata = mf.readfast(x) | |
2081 for f, n in mdata.iteritems(): | |
2082 if f in changedfiles: | |
2083 fnodes[f].setdefault(n, clnode) | |
2084 count[0] += 1 | |
2085 progress(_bundling, count[0], | |
2086 unit=_manifests, total=count[1]) | |
2087 return clnode | |
2088 else: | |
2089 progress(_bundling, count[0], item=fstate[0], | |
2090 unit=_files, total=count[1]) | |
2091 return fstate[1][x] | |
2092 | |
2093 bundler.start(lookup) | |
2094 | |
2095 def getmfnodes(): | |
2096 for f in changedfiles: | |
2097 fnodes[f] = {} | |
2098 bundler.count[:] = [0, len(mfs)] | |
2099 return prune(mf, mfs) | |
2100 def getfiles(): | |
2101 mfs.clear() | |
2102 return changedfiles | |
2103 def getfilenodes(fname, filerevlog): | |
2104 if fastpathlinkrev: | |
2105 ln, llr = filerevlog.node, filerevlog.linkrev | |
2106 def genfilenodes(): | |
2107 for r in filerevlog: | |
2108 linkrev = llr(r) | |
2109 if linkrev not in commonrevs: | |
2110 yield filerevlog.node(r), cl.node(linkrev) | |
2111 fnodes[fname] = dict(genfilenodes()) | |
2112 fstate[0] = fname | |
2113 fstate[1] = fnodes.pop(fname, {}) | |
2114 return prune(filerevlog, fstate[1]) | |
2115 | |
2116 gengroup = bundler.generate(csets, getmfnodes, getfiles, getfilenodes, | |
2117 source) | |
2118 return changegroup.unbundle10(util.chunkbuffer(gengroup), 'UN') | 2048 return changegroup.unbundle10(util.chunkbuffer(gengroup), 'UN') |
2119 | 2049 |
2120 def changegroup(self, basenodes, source): | 2050 def changegroup(self, basenodes, source): |
2121 # to avoid a race we use changegroupsubset() (issue1320) | 2051 # to avoid a race we use changegroupsubset() (issue1320) |
2122 return self.changegroupsubset(basenodes, self.heads(), source) | 2052 return self.changegroupsubset(basenodes, self.heads(), source) |