Patchwork [1,of,3,STABLE] changegroup: fix the scope of a try finally

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 6, 2015, 6:06 p.m.
Message ID <03916de16fe8f511a48b.1446833219@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/11305/
State Accepted
Headers show

Comments

Pierre-Yves David - Nov. 6, 2015, 6:06 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1446831546 18000
#      Fri Nov 06 12:39:06 2015 -0500
# Branch stable
# Node ID 03916de16fe8f511a48b860bf8b7956d79ea8ef9
# Parent  10a1a4b3e775d6024a82937df6bcc4188a315124
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 03916de16fe8
changegroup: fix the scope of a try finally

The try finally is here to ensure we release the just-created transaction.
Therefore we should not do half a dozen operations before actually entry the try
scope.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -320,23 +320,23 @@  class cg1unpacker(object):
             return cl.rev(x)
 
         changesets = files = revisions = 0
 
         tr = repo.transaction("\n".join([srctype, util.hidepassword(url)]))
-        # The transaction could have been created before and already
-        # carries 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)
+        try:
+            # The transaction could have been created before and already
+            # carries 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)
 
-        # write changelog data to temp files so concurrent readers will not see
-        # inconsistent view
-        cl = repo.changelog
-        cl.delayupdate(tr)
-        oldheads = cl.heads()
-        try:
+            # write changelog data to temp files so concurrent readers will not see
+            # inconsistent view
+            cl = repo.changelog
+            cl.delayupdate(tr)
+            oldheads = cl.heads()
             repo.hook('prechangegroup', throw=True, **tr.hookargs)
 
             trp = weakref.proxy(tr)
             # pull off the changeset group
             repo.ui.status(_("adding changesets\n"))