Patchwork D9714: shelve: extract some repeated creation of shelf instances to variables

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2021, 8:37 p.m.
Message ID <differential-rev-PHID-DREV-upx72rbfahzrls5wssqj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48025/
State Superseded
Headers show

Comments

phabricator - Jan. 8, 2021, 8:37 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This just looks cleaner to me; I'd be surprised if there's any
  measurable performance improvement.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -463,10 +463,11 @@ 
 
 def _shelvecreatedcommit(repo, node, name, match):
     info = {b'node': hex(node)}
-    Shelf(repo, name).writeinfo(info)
+    shelf = Shelf(repo, name)
+    shelf.writeinfo(info)
     bases = list(mutableancestors(repo[node]))
-    Shelf(repo, name).writebundle(bases, node)
-    with Shelf(repo, name).open_patch(b'wb') as fp:
+    shelf.writebundle(bases, node)
+    with shelf.open_patch(b'wb') as fp:
         cmdutil.exportfile(
             repo, [node], fp, opts=mdiff.diffopts(git=True), match=match
         )
@@ -602,11 +603,12 @@ 
         raise error.InputError(_(b'no shelved changes specified!'))
     with repo.wlock():
         for name in pats:
-            if not Shelf(repo, name).exists():
+            shelf = Shelf(repo, name)
+            if not shelf.exists():
                 raise error.InputError(
                     _(b"shelved change '%s' not found") % name
                 )
-            Shelf(repo, name).movetobackup()
+            shelf.movetobackup()
             cleanupoldbackups(repo)
 
 
@@ -875,16 +877,17 @@ 
     """Recreate commit in the repository during the unshelve"""
     repo = repo.unfiltered()
     node = None
-    if Shelf(repo, basename).hasinfo():
-        node = Shelf(repo, basename).readinfo()[b'node']
+    shelf = Shelf(repo, basename)
+    if shelf.hasinfo():
+        node = shelf.readinfo()[b'node']
     if node is None or node not in repo:
         with ui.configoverride({(b'ui', b'quiet'): True}):
-            shelvectx = Shelf(repo, basename).applybundle(tr)
+            shelvectx = shelf.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:
             info = {b'node': hex(shelvectx.node())}
-            Shelf(repo, basename).writeinfo(info)
+            shelf.writeinfo(info)
     else:
         shelvectx = repo[node]