shelve: extract some repeated creation of shelf instances to variables
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 07 Jan 2021 23:32:19 -0800
changeset 46287 ae7a77a7ebc0
parent 46286 3b08f56c8a11
child 46288 61f8fc12e167
shelve: extract some repeated creation of shelf instances to variables This just looks cleaner to me; I'd be surprised if there's any measurable performance improvement. Differential Revision: https://phab.mercurial-scm.org/D9714
mercurial/shelve.py
--- a/mercurial/shelve.py	Thu Jan 07 23:18:24 2021 -0800
+++ b/mercurial/shelve.py	Thu Jan 07 23:32:19 2021 -0800
@@ -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]