Patchwork [09,of,16] pull: move transaction tracking logic on the object

login
register
mail settings
Submitter Pierre-Yves David
Date April 17, 2013, 3:58 p.m.
Message ID <e6ecd45da44df1349d05.1366214324@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/1397/
State Deferred, archived
Headers show

Comments

Pierre-Yves David - April 17, 2013, 3:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1366213631 -7200
#      Wed Apr 17 17:47:11 2013 +0200
# Node ID e6ecd45da44df1349d05615753963759a5b52ef8
# Parent  2aa3dc70d3130eeb31e756e60c9956e756e0e03c
pull: move transaction tracking logic on the object

The transaction is open lazily during pull. We may have not pull any new
changesets but have some obsolescence markers to add.

This subtlety Makes it more complicated to extract various step of the pull as
they have to collaborate on this. We move the transaction reference on the
object to ease the extraction.

Patch

diff --git a/mercurial/exchangeutil.py b/mercurial/exchangeutil.py
--- a/mercurial/exchangeutil.py
+++ b/mercurial/exchangeutil.py
@@ -241,30 +241,31 @@  class pulloperation(object):
     def __init__(self, repo, remote, heads=None, force=False):
         self.repo = repo
         self.remote = remote
         self.heads = heads
         self.force = force
+        self._trname = 'pull\n' + util.hidepassword(remote.url())
+        # don't open transaction for nothing or you break future useful
+        # rollback call
+        self._tr = None # transaction code
+
 
     def perform(self):
         repo = self.repo
         remote = self.remote
         heads = self.heads
-        # don't open transaction for nothing or you break future useful
-        # rollback call
-        tr = None
-        trname = 'pull\n' + util.hidepassword(remote.url())
         lock = repo.lock()
         try:
             tmp = discovery.findcommonincoming(repo, remote, heads=heads,
                                                force=self.force)
             common, fetch, rheads = tmp
             if not fetch:
                 repo.ui.status(_("no changes found\n"))
                 added = []
                 result = 0
             else:
-                tr = repo.transaction(trname)
+                self._tr = repo.transaction(self._trname)
                 if heads is None and list(common) == [nullid]:
                     repo.ui.status(_("requesting all changes\n"))
                 elif heads is None and remote.capable('changegroupsubset'):
                     # issue1320, avoid a race if remote changed after discovery
                     heads = rheads
@@ -315,20 +316,20 @@  class pulloperation(object):
 
             if obsolete._enabled:
                 repo.ui.debug('fetching remote obsolete markers\n')
                 remoteobs = remote.listkeys('obsolete')
                 if 'dump0' in remoteobs:
-                    if tr is None:
-                        tr = repo.transaction(trname)
+                    if self._tr is None:
+                        self._tr = repo.transaction(self._trname)
                     for key in sorted(remoteobs, reverse=True):
                         if key.startswith('dump'):
                             data = base85.b85decode(remoteobs[key])
-                            repo.obsstore.mergemarkers(tr, data)
+                            repo.obsstore.mergemarkers(self._tr, data)
                     repo.invalidatevolatilesets()
-            if tr is not None:
-                tr.close()
+            if self._tr is not None:
+                self._tr.close()
         finally:
-            if tr is not None:
-                tr.release()
+            if self._tr is not None:
+                self._tr.release()
             lock.release()
 
         return result