Patchwork D9740: shelve: use listshelves() in cleanupoldbackups()

login
register
mail settings
Submitter phabricator
Date Jan. 12, 2021, 10:49 p.m.
Message ID <differential-rev-PHID-DREV-hmz47yhc3yuwqfnmoeyu-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48051/
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
  With this patch, there are no more assumptions outside the `Shelf`
  class about which files (`.patch`, `.hg`, `.shelve`) make up a
  shelf. As such, this finishes the preparations for making phase-based
  shelve (perhaps optionally) not write the `.patch` and `.hg` files.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -325,19 +325,17 @@ 
 def cleanupoldbackups(repo):
     vfs = vfsmod.vfs(repo.vfs.join(backupdir))
     maxbackups = repo.ui.configint(b'shelve', b'maxbackups')
-    hgfiles = [f for f in vfs.listdir() if f.endswith(b'.' + patchextension)]
-    hgfiles = sorted([(vfs.stat(f)[stat.ST_MTIME], f) for f in hgfiles])
+    hgfiles = listshelves(vfs)
     if maxbackups > 0 and maxbackups < len(hgfiles):
-        bordermtime = hgfiles[-maxbackups][0]
+        bordermtime = hgfiles[maxbackups - 1][0]
     else:
         bordermtime = None
-    for mtime, f in hgfiles[: len(hgfiles) - maxbackups]:
+    for mtime, name in hgfiles[maxbackups:]:
         if mtime == bordermtime:
             # keep it, because timestamp can't decide exact order of backups
             continue
-        base = f[: -(1 + len(patchextension))]
         for ext in shelvefileextensions:
-            vfs.tryunlink(base + b'.' + ext)
+            vfs.tryunlink(name + b'.' + ext)
 
 
 def _backupactivebookmark(repo):