changegroup: delete "if True" and reflow
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 15 Jun 2017 23:23:47 -0700
changeset 32931 b08431e1b062
parent 32930 af31d531dda0
child 32932 240183a04429
changegroup: delete "if True" and reflow
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Thu Jun 15 22:46:38 2017 -0700
+++ b/mercurial/changegroup.py	Thu Jun 15 23:23:47 2017 -0700
@@ -279,151 +279,149 @@
         changesets = files = revisions = 0
 
         try:
-            if True:
-                # The transaction may already carry source information. In this
-                # case we use the top level data. We overwrite the argument
-                # because we need to use the top level value (if they exist)
-                # in this function.
-                srctype = tr.hookargs.setdefault('source', srctype)
-                url = tr.hookargs.setdefault('url', url)
-                repo.hook('prechangegroup', throw=True, **tr.hookargs)
+            # The transaction may already carry source information. In this
+            # case we use the top level data. We overwrite the argument
+            # because we need to use the top level value (if they exist)
+            # in this function.
+            srctype = tr.hookargs.setdefault('source', srctype)
+            url = tr.hookargs.setdefault('url', url)
+            repo.hook('prechangegroup', throw=True, **tr.hookargs)
 
-                # write changelog data to temp files so concurrent readers
-                # will not see an inconsistent view
-                cl = repo.changelog
-                cl.delayupdate(tr)
-                oldheads = set(cl.heads())
+            # write changelog data to temp files so concurrent readers
+            # will not see an inconsistent view
+            cl = repo.changelog
+            cl.delayupdate(tr)
+            oldheads = set(cl.heads())
 
-                trp = weakref.proxy(tr)
-                # pull off the changeset group
-                repo.ui.status(_("adding changesets\n"))
-                clstart = len(cl)
-                class prog(object):
-                    def __init__(self, step, total):
-                        self._step = step
-                        self._total = total
-                        self._count = 1
-                    def __call__(self):
-                        repo.ui.progress(self._step, self._count,
-                                         unit=_('chunks'), total=self._total)
-                        self._count += 1
-                self.callback = prog(_('changesets'), expectedtotal)
+            trp = weakref.proxy(tr)
+            # pull off the changeset group
+            repo.ui.status(_("adding changesets\n"))
+            clstart = len(cl)
+            class prog(object):
+                def __init__(self, step, total):
+                    self._step = step
+                    self._total = total
+                    self._count = 1
+                def __call__(self):
+                    repo.ui.progress(self._step, self._count, unit=_('chunks'),
+                                     total=self._total)
+                    self._count += 1
+            self.callback = prog(_('changesets'), expectedtotal)
 
-                efiles = set()
-                def onchangelog(cl, node):
-                    efiles.update(cl.readfiles(node))
+            efiles = set()
+            def onchangelog(cl, node):
+                efiles.update(cl.readfiles(node))
 
-                self.changelogheader()
-                cgnodes = cl.addgroup(self, csmap, trp,
-                                      addrevisioncb=onchangelog)
-                efiles = len(efiles)
+            self.changelogheader()
+            cgnodes = cl.addgroup(self, csmap, trp, addrevisioncb=onchangelog)
+            efiles = len(efiles)
 
-                if not (cgnodes or emptyok):
-                    raise error.Abort(_("received changelog group is empty"))
-                clend = len(cl)
-                changesets = clend - clstart
-                repo.ui.progress(_('changesets'), None)
-                self.callback = None
+            if not (cgnodes or emptyok):
+                raise error.Abort(_("received changelog group is empty"))
+            clend = len(cl)
+            changesets = clend - clstart
+            repo.ui.progress(_('changesets'), None)
+            self.callback = None
 
-                # pull off the manifest group
-                repo.ui.status(_("adding manifests\n"))
-                self._unpackmanifests(repo, revmap, trp, prog, changesets)
+            # pull off the manifest group
+            repo.ui.status(_("adding manifests\n"))
+            self._unpackmanifests(repo, revmap, trp, prog, changesets)
 
-                needfiles = {}
-                if repo.ui.configbool('server', 'validate', default=False):
-                    cl = repo.changelog
-                    ml = repo.manifestlog
-                    # validate incoming csets have their manifests
-                    for cset in xrange(clstart, clend):
-                        mfnode = cl.changelogrevision(cset).manifest
-                        mfest = ml[mfnode].readdelta()
-                        # store file cgnodes we must see
-                        for f, n in mfest.iteritems():
-                            needfiles.setdefault(f, set()).add(n)
+            needfiles = {}
+            if repo.ui.configbool('server', 'validate', default=False):
+                cl = repo.changelog
+                ml = repo.manifestlog
+                # validate incoming csets have their manifests
+                for cset in xrange(clstart, clend):
+                    mfnode = cl.changelogrevision(cset).manifest
+                    mfest = ml[mfnode].readdelta()
+                    # store file cgnodes we must see
+                    for f, n in mfest.iteritems():
+                        needfiles.setdefault(f, set()).add(n)
 
-                # process the files
-                repo.ui.status(_("adding file changes\n"))
-                newrevs, newfiles = _addchangegroupfiles(
-                    repo, self, revmap, trp, efiles, needfiles)
-                revisions += newrevs
-                files += newfiles
+            # process the files
+            repo.ui.status(_("adding file changes\n"))
+            newrevs, newfiles = _addchangegroupfiles(
+                repo, self, revmap, trp, efiles, needfiles)
+            revisions += newrevs
+            files += newfiles
 
-                deltaheads = 0
-                if oldheads:
-                    heads = cl.heads()
-                    deltaheads = len(heads) - len(oldheads)
-                    for h in heads:
-                        if h not in oldheads and repo[h].closesbranch():
-                            deltaheads -= 1
-                htext = ""
-                if deltaheads:
-                    htext = _(" (%+d heads)") % deltaheads
+            deltaheads = 0
+            if oldheads:
+                heads = cl.heads()
+                deltaheads = len(heads) - len(oldheads)
+                for h in heads:
+                    if h not in oldheads and repo[h].closesbranch():
+                        deltaheads -= 1
+            htext = ""
+            if deltaheads:
+                htext = _(" (%+d heads)") % deltaheads
 
-                repo.ui.status(_("added %d changesets"
-                                 " with %d changes to %d files%s\n")
-                                 % (changesets, revisions, files, htext))
-                repo.invalidatevolatilesets()
+            repo.ui.status(_("added %d changesets"
+                             " with %d changes to %d files%s\n")
+                             % (changesets, revisions, files, htext))
+            repo.invalidatevolatilesets()
 
-                if changesets > 0:
-                    if 'node' not in tr.hookargs:
-                        tr.hookargs['node'] = hex(cl.node(clstart))
-                        tr.hookargs['node_last'] = hex(cl.node(clend - 1))
-                        hookargs = dict(tr.hookargs)
-                    else:
-                        hookargs = dict(tr.hookargs)
-                        hookargs['node'] = hex(cl.node(clstart))
-                        hookargs['node_last'] = hex(cl.node(clend - 1))
-                    repo.hook('pretxnchangegroup', throw=True, **hookargs)
+            if changesets > 0:
+                if 'node' not in tr.hookargs:
+                    tr.hookargs['node'] = hex(cl.node(clstart))
+                    tr.hookargs['node_last'] = hex(cl.node(clend - 1))
+                    hookargs = dict(tr.hookargs)
+                else:
+                    hookargs = dict(tr.hookargs)
+                    hookargs['node'] = hex(cl.node(clstart))
+                    hookargs['node_last'] = hex(cl.node(clend - 1))
+                repo.hook('pretxnchangegroup', throw=True, **hookargs)
 
-                added = [cl.node(r) for r in xrange(clstart, clend)]
-                if srctype in ('push', 'serve'):
-                    # Old servers can not push the boundary themselves.
-                    # New servers won't push the boundary if changeset already
-                    # exists locally as secret
-                    #
-                    # We should not use added here but the list of all change in
-                    # the bundle
-                    if repo.publishing():
-                        phases.advanceboundary(repo, tr, phases.public, cgnodes)
-                    else:
-                        # Those changesets have been pushed from the
-                        # outside, their phases are going to be pushed
-                        # alongside. Therefor `targetphase` is
-                        # ignored.
-                        phases.advanceboundary(repo, tr, phases.draft, cgnodes)
-                        phases.retractboundary(repo, tr, phases.draft, added)
-                elif srctype != 'strip':
-                    # publishing only alter behavior during push
-                    #
-                    # strip should not touch boundary at all
-                    phases.retractboundary(repo, tr, targetphase, added)
+            added = [cl.node(r) for r in xrange(clstart, clend)]
+            if srctype in ('push', 'serve'):
+                # Old servers can not push the boundary themselves.
+                # New servers won't push the boundary if changeset already
+                # exists locally as secret
+                #
+                # We should not use added here but the list of all change in
+                # the bundle
+                if repo.publishing():
+                    phases.advanceboundary(repo, tr, phases.public, cgnodes)
+                else:
+                    # Those changesets have been pushed from the
+                    # outside, their phases are going to be pushed
+                    # alongside. Therefor `targetphase` is
+                    # ignored.
+                    phases.advanceboundary(repo, tr, phases.draft, cgnodes)
+                    phases.retractboundary(repo, tr, phases.draft, added)
+            elif srctype != 'strip':
+                # publishing only alter behavior during push
+                #
+                # strip should not touch boundary at all
+                phases.retractboundary(repo, tr, targetphase, added)
 
-                if changesets > 0:
+            if changesets > 0:
 
-                    def runhooks():
-                        # These hooks run when the lock releases, not when the
-                        # transaction closes. So it's possible for the changelog
-                        # to have changed since we last saw it.
-                        if clstart >= len(repo):
-                            return
+                def runhooks():
+                    # These hooks run when the lock releases, not when the
+                    # transaction closes. So it's possible for the changelog
+                    # to have changed since we last saw it.
+                    if clstart >= len(repo):
+                        return
 
-                        repo.hook("changegroup", **hookargs)
+                    repo.hook("changegroup", **hookargs)
 
-                        for n in added:
-                            args = hookargs.copy()
-                            args['node'] = hex(n)
-                            del args['node_last']
-                            repo.hook("incoming", **args)
+                    for n in added:
+                        args = hookargs.copy()
+                        args['node'] = hex(n)
+                        del args['node_last']
+                        repo.hook("incoming", **args)
 
-                        newheads = [h for h in repo.heads()
-                                    if h not in oldheads]
-                        repo.ui.log("incoming",
-                                    "%s incoming changes - new heads: %s\n",
-                                    len(added),
-                                    ', '.join([hex(c[:6]) for c in newheads]))
+                    newheads = [h for h in repo.heads()
+                                if h not in oldheads]
+                    repo.ui.log("incoming",
+                                "%s incoming changes - new heads: %s\n",
+                                len(added),
+                                ', '.join([hex(c[:6]) for c in newheads]))
 
-                    tr.addpostclose('changegroup-runhooks-%020i' % clstart,
-                                    lambda tr: repo._afterlock(runhooks))
+                tr.addpostclose('changegroup-runhooks-%020i' % clstart,
+                                lambda tr: repo._afterlock(runhooks))
         finally:
             repo.ui.flush()
         # never return 0 here: