Patchwork D9713: shelve: teach new shelf class to check if .shelve file exists

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2021, 8:37 p.m.
Message ID <differential-rev-PHID-DREV-f5mbjxvbcdvcg4sa2i7j-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48024/
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 removes the only remaining use for `shelvedfile`, so the class
  now goes away.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -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}):