Patchwork D9742: shelve: add a method for deleting shelf to new shelf class

login
register
mail settings
Submitter phabricator
Date Jan. 12, 2021, 10:49 p.m.
Message ID <differential-rev-PHID-DREV-uhhjhdyp22uespfyrxvb-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48053/
State Superseded
Headers show

Comments

phabricator - Jan. 12, 2021, 10:49 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is not necessary for my future changes, but it's more consistent
  to encapsulate the knowledge of the various files in the `Shelf`
  class.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -86,6 +86,10 @@ 
     def open(repo, name):
         return Shelf(vfsmod.vfs(repo.vfs.join(shelvedir)), name)
 
+    @staticmethod
+    def open_backup(repo, name):
+        return Shelf(vfsmod.vfs(repo.vfs.join(backupdir)), name)
+
     def exists(self):
         return self.vfs.exists(self.name + b'.patch') and self.vfs.exists(
             self.name + b'.hg'
@@ -181,6 +185,10 @@ 
                     self._backupfilename(backupvfs, filename),
                 )
 
+    def delete(self):
+        for ext in shelvefileextensions:
+            self.vfs.tryunlink(self.name + b'.' + ext)
+
 
 class shelvedstate(object):
     """Handle persistence during unshelving operations.
@@ -332,8 +340,7 @@ 
         if mtime == bordermtime:
             # keep it, because timestamp can't decide exact order of backups
             continue
-        for ext in shelvefileextensions:
-            vfs.tryunlink(name + b'.' + ext)
+        Shelf.open_backup(repo, name).delete()
 
 
 def _backupactivebookmark(repo):