changeset 46293:9cdef4c41c94

shelve: use listshelves() in cleanupoldbackups() 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. Differential Revision: https://phab.mercurial-scm.org/D9740
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 11 Jan 2021 23:06:45 -0800
parents 3204a35e5c7e
children d3b226b6c8c6
files mercurial/shelve.py
diffstat 1 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/shelve.py	Mon Jan 11 23:02:20 2021 -0800
+++ b/mercurial/shelve.py	Mon Jan 11 23:06:45 2021 -0800
@@ -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):