# HG changeset patch # User Gregory Szorc # Date 2018-08-07 22:45:56 # Node ID b83e9c503f2f4256d14451048d2f8ebe0728f2f3 # Parent 40374b4a780fb082c1632eba9cb64765d4807887 changegroup: define linknodes callbacks in generatefiles() This is how it is done everywhere else. But the logic here is a bit more complex because shallow clone needs to reference the original linknode implementation. But at least now all function implementations are defined in the same place. Differential Revision: https://phab.mercurial-scm.org/D4191 diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -819,19 +819,9 @@ class cgpacker(object): mfs.clear() clrevs = set(cl.rev(x) for x in clnodes) - if not fastpathlinkrev: - def linknodes(unused, fname): - return fnodes.get(fname, {}) - else: - cln = cl.node - def linknodes(filerevlog, fname): - llr = filerevlog.linkrev - fln = filerevlog.node - revs = ((r, llr(r)) for r in filerevlog) - return dict((fln(r), cln(lr)) for r, lr in revs if lr in clrevs) - - for chunk in self.generatefiles(changedfiles, linknodes, commonrevs, - source, mfdicts): + for chunk in self.generatefiles(changedfiles, commonrevs, + source, mfdicts, fastpathlinkrev, + fnodes, clrevs): yield chunk yield self._close() @@ -986,16 +976,28 @@ class cgpacker(object): yield self._manifestsend # The 'source' parameter is useful for extensions - def generatefiles(self, changedfiles, linknodes, commonrevs, source, - mfdicts): + def generatefiles(self, changedfiles, commonrevs, source, + mfdicts, fastpathlinkrev, fnodes, clrevs): changedfiles = list(filter(self._filematcher, changedfiles)) + if not fastpathlinkrev: + def normallinknodes(unused, fname): + return fnodes.get(fname, {}) + else: + cln = self._repo.changelog.node + + def normallinknodes(store, fname): + flinkrev = store.linkrev + fnode = store.node + revs = ((r, flinkrev(r)) for r in store) + return dict((fnode(r), cln(lr)) + for r, lr in revs if lr in clrevs) + if self._isshallow: # In a shallow clone, the linknodes callback needs to also include # those file nodes that are in the manifests we sent but weren't # introduced by those manifests. commonctxs = [self._repo[c] for c in commonrevs] - oldlinknodes = linknodes clrev = self._repo.changelog.rev # Defining this function has a side-effect of overriding the @@ -1008,7 +1010,7 @@ class cgpacker(object): self._clrevtolocalrev[c.rev()] = flog.rev(fnode) except error.ManifestLookupError: pass - links = oldlinknodes(flog, fname) + links = normallinknodes(flog, fname) if len(links) != len(mfdicts): for mf, lr in mfdicts: fnode = mf.get(fname, None) @@ -1017,6 +1019,8 @@ class cgpacker(object): elif fnode: links[fnode] = lr return links + else: + linknodes = normallinknodes return self._generatefiles(changedfiles, linknodes, commonrevs, source)