Patchwork D5456: shelve: pass transaction around to clarify where it's used

login
register
mail settings
Submitter phabricator
Date Dec. 20, 2018, 12:02 p.m.
Message ID <86894641db3f84b4487006e693f5e616@localhost.localdomain>
Download mbox | patch
Permalink /patch/37266/
State Not Applicable
Headers show

Comments

phabricator - Dec. 20, 2018, 12:02 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGa06dc62f1c82: shelve: pass transaction around to clarify where it&#039;s used (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5456?vs=12904&id=12916

REVISION DETAIL
  https://phab.mercurial-scm.org/D5456

AFFECTED FILES
  hgext/shelve.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -137,15 +137,14 @@ 
                 raise
             raise error.Abort(_("shelved change '%s' not found") % self.name)
 
-    def applybundle(self):
+    def applybundle(self, tr):
         fp = self.opener()
         try:
             targetphase = phases.internal
             if not phases.supportinternal(self.repo):
                 targetphase = phases.secret
             gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
             pretip = self.repo['tip']
-            tr = self.repo.currenttransaction()
             bundle2.applybundle(self.repo, gen, tr,
                                 source='unshelve',
                                 url='bundle:' + self.vfs.join(self.fname),
@@ -324,10 +323,9 @@ 
     if mark:
         bookmarks.activate(repo, mark)
 
-def _aborttransaction(repo):
+def _aborttransaction(repo, tr):
     '''Abort current transaction for shelve/unshelve, but keep dirstate
     '''
-    tr = repo.currenttransaction()
     dirstatebackupname = 'dirstate.shelve'
     narrowspecbackupname = 'narrowspec.shelve'
     repo.dirstate.savebackup(tr, dirstatebackupname)
@@ -444,12 +442,11 @@ 
         extra['shelve_unknown'] = '\0'.join(s.unknown)
         repo[None].add(s.unknown)
 
-def _finishshelve(repo):
+def _finishshelve(repo, tr):
     if phases.supportinternal(repo):
-        tr = repo.currenttransaction()
         tr.close()
     else:
-        _aborttransaction(repo)
+        _aborttransaction(repo, tr)
 
 def createcmd(ui, repo, pats, opts):
     """subcommand that creates a new shelve"""
@@ -516,7 +513,7 @@ 
         if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
             repo.dirstate.setbranch(origbranch)
 
-        _finishshelve(repo)
+        _finishshelve(repo, tr)
     finally:
         _restoreactivebookmark(repo, activebookmark)
         lockmod.release(tr, lock)
@@ -791,15 +788,15 @@ 
     tmpwctx = repo[node]
     return tmpwctx, addedbefore
 
-def _unshelverestorecommit(ui, repo, basename):
+def _unshelverestorecommit(ui, repo, tr, basename):
     """Recreate commit in the repository during the unshelve"""
     repo = repo.unfiltered()
     node = None
     if shelvedfile(repo, basename, 'shelve').exists():
         node = shelvedfile(repo, basename, 'shelve').readinfo()['node']
     if node is None or node not in repo:
         with ui.configoverride({('ui', 'quiet'): True}):
-            shelvectx = shelvedfile(repo, basename, 'hg').applybundle()
+            shelvectx = shelvedfile(repo, basename, 'hg').applybundle(tr)
         # We might not strip the unbundled changeset, so we should keep track of
         # the unshelve node in case we need to reuse it (eg: unshelve --keep)
         if node is None:
@@ -879,7 +876,7 @@ 
     # hooks still fire and try to operate on the missing commits.
     # Clean up manually to prevent this.
     repo.unfiltered().changelog.strip(oldtiprev, tr)
-    _aborttransaction(repo)
+    _aborttransaction(repo, tr)
 
 def _checkunshelveuntrackedproblems(ui, repo, shelvectx):
     """Check potential problems which may result from working
@@ -1023,7 +1020,7 @@ 
         activebookmark = _backupactivebookmark(repo)
         tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,
                                                          tmpwctx)
-        repo, shelvectx = _unshelverestorecommit(ui, repo, basename)
+        repo, shelvectx = _unshelverestorecommit(ui, repo, tr, basename)
         _checkunshelveuntrackedproblems(ui, repo, shelvectx)
         branchtorestore = ''
         if shelvectx.branch() != shelvectx.p1().branch():