# HG changeset patch # User Pierre-Yves David # Date 2014-04-01 22:21:56 # Node ID 0ac83e4e4f7c5e5fe3fde9b1f91359be66ed72c3 # Parent de60ca3a390e5aa8d5e6bced6dca4807b681401b localrepo: move the addchangegroupfiles method in changegroup module This is a gratuitous code move aimed at reducing the localrepo bloatness. The method had a single caller, far too few for being kept in local repo. diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -9,7 +9,7 @@ from i18n import _ from node import nullrev, nullid, hex import mdiff, util, dagutil import struct, os, bz2, zlib, tempfile -import discovery +import discovery, error _BUNDLE10_DELTA_HEADER = "20s20s20s20s" @@ -514,3 +514,43 @@ def changegroup(repo, basenodes, source) # to avoid a race we use changegroupsubset() (issue1320) return changegroupsubset(repo, basenodes, repo.heads(), source) +def addchangegroupfiles(repo, source, revmap, trp, pr, needfiles): + revisions = 0 + files = 0 + while True: + chunkdata = source.filelogheader() + if not chunkdata: + break + f = chunkdata["filename"] + repo.ui.debug("adding %s revisions\n" % f) + pr() + fl = repo.file(f) + o = len(fl) + if not fl.addgroup(source, revmap, trp): + raise util.Abort(_("received file revlog group is empty")) + revisions += len(fl) - o + files += 1 + if f in needfiles: + needs = needfiles[f] + for new in xrange(o, len(fl)): + n = fl.node(new) + if n in needs: + needs.remove(n) + else: + raise util.Abort( + _("received spurious file revlog entry")) + if not needs: + del needfiles[f] + repo.ui.progress(_('files'), None) + + for f, needs in needfiles.iteritems(): + fl = repo.file(f) + for n in needs: + try: + fl.rev(n) + except error.LookupError: + raise util.Abort( + _('missing file data for %s:%s - run hg verify') % + (f, hex(n))) + + return revisions, files diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1775,8 +1775,12 @@ class localrepository(object): pr.total = efiles source.callback = None - newrevs, newfiles = self.addchangegroupfiles(source, revmap, trp, - pr, needfiles) + newrevs, newfiles = changegroup.addchangegroupfiles(self, + source, + revmap, + trp, + pr, + needfiles) revisions += newrevs files += newfiles @@ -1864,46 +1868,6 @@ class localrepository(object): else: return dh + 1 - def addchangegroupfiles(self, source, revmap, trp, pr, needfiles): - revisions = 0 - files = 0 - while True: - chunkdata = source.filelogheader() - if not chunkdata: - break - f = chunkdata["filename"] - self.ui.debug("adding %s revisions\n" % f) - pr() - fl = self.file(f) - o = len(fl) - if not fl.addgroup(source, revmap, trp): - raise util.Abort(_("received file revlog group is empty")) - revisions += len(fl) - o - files += 1 - if f in needfiles: - needs = needfiles[f] - for new in xrange(o, len(fl)): - n = fl.node(new) - if n in needs: - needs.remove(n) - else: - raise util.Abort( - _("received spurious file revlog entry")) - if not needs: - del needfiles[f] - self.ui.progress(_('files'), None) - - for f, needs in needfiles.iteritems(): - fl = self.file(f) - for n in needs: - try: - fl.rev(n) - except error.LookupError: - raise util.Abort( - _('missing file data for %s:%s - run hg verify') % - (f, hex(n))) - - return revisions, files def stream_in(self, remote, requirements): lock = self.lock()