[Request] [+- ] D9700: shelve: introduce class representing a shelf
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Fri Jan 8 20:37:40 UTC 2021
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
I'm about to make phase-based shelve not write `.hg` and `.patch`
files. Having a class that represents a single shelf, regardless of
which files it uses will help. I'm starting small with just a
`.exists()` function. I plan to eventually remove the `shelvedfile`
class once all functionality has been moved to the new class.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D9700
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
@@ -170,6 +170,23 @@
return scmutil.simplekeyvaluefile(self.vfs, self.fname).read()
+class Shelf(object):
+ """Represents a shelf, including possibly multiple files storing it.
+
+ Old shelves will have a .patch and a .hg file. Newer shelves will
+ also have a .shelve file. This class abstracts away some of the
+ differences and lets you work with the shelf as a whole.
+ """
+
+ def __init__(self, repo, name):
+ self.repo = repo
+ self.name = name
+ self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
+
+ def exists(self):
+ return self.vfs.exists(self.name + b'.' + patchextension)
+
+
class shelvedstate(object):
"""Handle persistence during unshelving operations.
@@ -364,7 +381,7 @@
label = label.replace(b'.', b'_', 1)
if name:
- if shelvedfile(repo, name, patchextension).exists():
+ if Shelf(repo, name).exists():
e = _(b"a shelved change named '%s' already exists") % name
raise error.Abort(e)
@@ -378,7 +395,7 @@
else:
for n in gennames():
- if not shelvedfile(repo, n, patchextension).exists():
+ if not Shelf(repo, n).exists():
name = n
break
@@ -595,7 +612,7 @@
raise error.InputError(_(b'no shelved changes specified!'))
with repo.wlock():
for name in pats:
- if not shelvedfile(repo, name, patchextension).exists():
+ if not Shelf(repo, name).exists():
raise error.InputError(
_(b"shelved change '%s' not found") % name
)
@@ -682,7 +699,7 @@
pats = [sname]
for shelfname in pats:
- if not shelvedfile(repo, shelfname, patchextension).exists():
+ if not Shelf(repo, shelfname).exists():
raise error.Abort(_(b"cannot find shelf %s") % shelfname)
listcmd(ui, repo, pats, opts)
@@ -1104,7 +1121,7 @@
else:
basename = shelved[0]
- if not shelvedfile(repo, basename, patchextension).exists():
+ if not Shelf(repo, basename).exists():
raise error.InputError(_(b"shelved change '%s' not found") % basename)
return _dounshelve(ui, repo, basename, opts)
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/2023e772/attachment-0001.html>
More information about the Mercurial-patches
mailing list