# HG changeset patch # User Matt Mackall # Date 2011-03-28 16:18:56 # Node ID 9131724c3f4bade6216eb2c91608efa233d4a01a # Parent 66c54d2ebe72d4850bf35aa264be6c45f7b3d5e1 changegroup: combine infocollect and lookup callbacks diff --git a/contrib/shrink-revlog.py b/contrib/shrink-revlog.py --- a/contrib/shrink-revlog.py +++ b/contrib/shrink-revlog.py @@ -110,7 +110,10 @@ def writerevs(ui, r1, r2, order, tr): order = [r1.node(r) for r in order] # this is a bit ugly, but it works - lookup = lambda x: "%020d" % r1.linkrev(r1.rev(x)) + def lookup(x): + progress(x) + return "%020d" % r1.linkrev(r1.rev(x)) + unlookup = lambda x: int(x, 10) try: diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1529,11 +1529,15 @@ class localrepository(repo.repository): def gengroup(): # The set of changed files starts empty. changedfiles = set() + collect = changegroup.collector(cl, mfs, changedfiles) + def clookup(x): + collect(x) + return x # Create a changenode group generator that will call our functions # back to lookup the owning changenode and collect information. - group = cl.group(csets, lambda x: x, collect) + group = cl.group(csets, clookup) for count, chunk in enumerate(group): yield chunk # revlog.group yields three entries per node, so @@ -1548,9 +1552,12 @@ class localrepository(repo.repository): prune(mf, mfs) # Create a generator for the manifestnodes that calls our lookup # and data collection functions back. - group = mf.group(sorted(mfs, key=mf.rev), - lambda mnode: mfs[mnode], - filenode_collector(changedfiles)) + fcollect = filenode_collector(changedfiles) + def mlookup(x): + fcollect(x) + return mfs[x] + + group = mf.group(sorted(mfs, key=mf.rev), mlookup) for count, chunk in enumerate(group): yield chunk # see above comment for why we divide by 3 @@ -1577,9 +1584,12 @@ class localrepository(repo.repository): # Create a group generator and only pass in a changenode # lookup function as we need to collect no information # from filenodes. + def flookup(x): + return missingfnodes[x] + group = filerevlog.group( sorted(missingfnodes, key=filerevlog.rev), - lambda fnode: missingfnodes[fnode]) + flookup) for chunk in group: # even though we print the same progress on # most loop iterations, put the progress call @@ -1632,9 +1642,13 @@ class localrepository(repo.repository): # construct a list of all changed files changedfiles = set() mmfs = {} - collect = changegroup.collector(cl, mmfs, changedfiles) - for count, chunk in enumerate(cl.group(nodes, lambda x: x, collect)): + collect = changegroup.collector(cl, mmfs, changedfiles) + def clookup(x): + collect(x) + return x + + for count, chunk in enumerate(cl.group(nodes, clookup)): # revlog.group yields three entries per node, so # dividing by 3 gives an approximation of how many # nodes have been processed. @@ -1646,8 +1660,11 @@ class localrepository(repo.repository): mnfst = self.manifest nodeiter = gennodelst(mnfst) - for count, chunk in enumerate(mnfst.group(nodeiter, - lookuplinkrev_func(mnfst))): + mfunc = lookuplinkrev_func(mnfst) + def mlookup(x): + return mfunc(x) + + for count, chunk in enumerate(mnfst.group(nodeiter, mlookup)): # see above comment for why we divide by 3 self.ui.progress(_('bundling'), count / 3, unit=_('manifests'), total=changecount) @@ -1663,8 +1680,11 @@ class localrepository(repo.repository): if nodeiter: yield changegroup.chunkheader(len(fname)) yield fname - lookup = lookuplinkrev_func(filerevlog) - for chunk in filerevlog.group(nodeiter, lookup): + ffunc = lookuplinkrev_func(filerevlog) + def flookup(x): + return ffunc(x) + + for chunk in filerevlog.group(nodeiter, flookup): self.ui.progress( _('bundling'), idx, item=fname, total=efiles, unit=_('files')) diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1058,7 +1058,7 @@ class revlog(object): self._cache = (node, curr, text) return node - def group(self, nodelist, lookup, infocollect=None): + def group(self, nodelist, lookup): """Calculate a delta group, yielding a sequence of changegroup chunks (strings). @@ -1086,9 +1086,6 @@ class revlog(object): a, b = revs[r], revs[r + 1] nb = self.node(b) - if infocollect is not None: - infocollect(nb) - p = self.parents(nb) meta = nb + p[0] + p[1] + lookup(nb) if a == nullrev: