changeset 46292:3204a35e5c7e

shelve: make listshelves() list shelves in a given vfs Differential Revision: https://phab.mercurial-scm.org/D9739
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 11 Jan 2021 23:02:20 -0800
parents e2713c68b477
children 9cdef4c41c94
files mercurial/shelve.py
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/shelve.py	Tue Jan 12 08:07:59 2021 -0800
+++ b/mercurial/shelve.py	Mon Jan 11 23:02:20 2021 -0800
@@ -597,9 +597,10 @@
     """subcommand that deletes all shelves"""
 
     with repo.wlock():
+        vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
         backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
-        for _mtime, name in listshelves(repo):
-            Shelf.open(repo, name).movetobackup(backupvfs)
+        for _mtime, name in listshelves(vfs):
+            Shelf(vfs, name).movetobackup(backupvfs)
             cleanupoldbackups(repo)
 
 
@@ -619,10 +620,10 @@
             cleanupoldbackups(repo)
 
 
-def listshelves(repo):
+def listshelves(vfs):
     """return all shelves in repo as list of (time, name)"""
     try:
-        names = repo.vfs.listdir(shelvedir)
+        names = vfs.listdir()
     except OSError as err:
         if err.errno != errno.ENOENT:
             raise
@@ -634,7 +635,7 @@
         if name in seen:
             continue
         seen.add(name)
-        shelf = Shelf.open(repo, name)
+        shelf = Shelf(vfs, name)
         if not shelf.exists():
             continue
         mtime = shelf.mtime()
@@ -650,7 +651,8 @@
         width = ui.termwidth()
     namelabel = b'shelve.newest'
     ui.pager(b'shelve')
-    for mtime, name in listshelves(repo):
+    vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
+    for mtime, name in listshelves(vfs):
         if pats and name not in pats:
             continue
         ui.write(name, label=namelabel)
@@ -691,7 +693,8 @@
 def patchcmds(ui, repo, pats, opts):
     """subcommand that displays shelves"""
     if len(pats) == 0:
-        shelves = listshelves(repo)
+        vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
+        shelves = listshelves(vfs)
         if not shelves:
             raise error.Abort(_(b"there are no shelves to show"))
         mtime, name = shelves[0]
@@ -1111,7 +1114,8 @@
     elif len(shelved) > 1:
         raise error.InputError(_(b'can only unshelve one change at a time'))
     elif not shelved:
-        shelved = listshelves(repo)
+        vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
+        shelved = listshelves(vfs)
         if not shelved:
             raise error.StateError(_(b'no shelved changes to apply!'))
         basename = shelved[0][1]