[Request] [+- ] D9714: shelve: extract some repeated creation of shelf instances to variables
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Fri Jan 8 20:37:51 UTC 2021
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
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]
To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210108/850d39b2/attachment-0001.html>
More information about the Mercurial-patches
mailing list