changeset 46286:3b08f56c8a11

shelve: teach new shelf class to check if .shelve file exists This removes the only remaining use for `shelvedfile`, so the class now goes away. Differential Revision: https://phab.mercurial-scm.org/D9713
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Jan 2021 23:18:24 -0800
parents e79f8ae0901b
children ae7a77a7ebc0
files mercurial/shelve.py
diffstat 1 files changed, 4 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/shelve.py	Thu Jan 07 22:45:17 2021 -0800
+++ b/mercurial/shelve.py	Thu Jan 07 23:18:24 2021 -0800
@@ -72,24 +72,6 @@
 shelveuser = b'shelve@localhost'
 
 
-class shelvedfile(object):
-    """Helper for the file storing a single shelve
-
-    Handles common functions on shelve files (.hg/.patch) using
-    the vfs layer"""
-
-    def __init__(self, repo, name, filetype=None):
-        self.name = name
-        self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
-        if filetype:
-            self.fname = name + b'.' + filetype
-        else:
-            self.fname = name
-
-    def exists(self):
-        return self.vfs.exists(self.fname)
-
-
 class Shelf(object):
     """Represents a shelf, including possibly multiple files storing it.
 
@@ -113,6 +95,9 @@
     def writeinfo(self, info):
         scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info)
 
+    def hasinfo(self):
+        return self.vfs.exists(self.name + b'.shelve')
+
     def readinfo(self):
         return scmutil.simplekeyvaluefile(
             self.vfs, self.name + b'.shelve'
@@ -890,7 +875,7 @@
     """Recreate commit in the repository during the unshelve"""
     repo = repo.unfiltered()
     node = None
-    if shelvedfile(repo, basename, b'shelve').exists():
+    if Shelf(repo, basename).hasinfo():
         node = Shelf(repo, basename).readinfo()[b'node']
     if node is None or node not in repo:
         with ui.configoverride({(b'ui', b'quiet'): True}):