# HG changeset patch # User Martin von Zweigbergk # Date 2021-01-12 07:06:45 # Node ID 9cdef4c41c945a88699875ff1e9ba173dc0ee77f # Parent 3204a35e5c7ed3f840bb2b73933f7ab770dfa305 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 diff --git a/mercurial/shelve.py b/mercurial/shelve.py --- a/mercurial/shelve.py +++ b/mercurial/shelve.py @@ -325,19 +325,17 @@ class shelvedstate(object): 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):