Patchwork D9739: shelve: make listshelves() list shelves in a given vfs

login
register
mail settings
Submitter phabricator
Date Jan. 12, 2021, 10:49 p.m.
Message ID <differential-rev-PHID-DREV-3atl2tqmrbh3ssnyichu-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48050/
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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -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]