shelve: make listshelves() return shelf names instead of filenames
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 07 Jan 2021 15:24:46 -0800
changeset 46281 a34607b6d320
parent 46280 7e300d297547
child 46282 0a69f9e640ec
shelve: make listshelves() return shelf names instead of filenames All three callers now prefer the shelf name over the filename (already before my recent patches, two out of three callers preferred the shelf name). Differential Revision: https://phab.mercurial-scm.org/D9708
mercurial/shelve.py
--- a/mercurial/shelve.py	Thu Jan 07 14:54:56 2021 -0800
+++ b/mercurial/shelve.py	Thu Jan 07 15:24:46 2021 -0800
@@ -630,7 +630,7 @@
 
 
 def listshelves(repo):
-    """return all shelves in repo as list of (time, filename)"""
+    """return all shelves in repo as list of (time, name)"""
     try:
         names = repo.vfs.readdir(shelvedir)
     except OSError as err:
@@ -643,7 +643,7 @@
         if not pfx or sfx != patchextension:
             continue
         mtime = Shelf(repo, pfx).mtime()
-        info.append((mtime, shelvedfile(repo, pfx).filename()))
+        info.append((mtime, pfx))
     return sorted(info, reverse=True)
 
 
@@ -656,22 +656,21 @@
     namelabel = b'shelve.newest'
     ui.pager(b'shelve')
     for mtime, name in listshelves(repo):
-        sname = util.split(name)[1]
-        if pats and sname not in pats:
+        if pats and name not in pats:
             continue
-        ui.write(sname, label=namelabel)
+        ui.write(name, label=namelabel)
         namelabel = b'shelve.name'
         if ui.quiet:
             ui.write(b'\n')
             continue
-        ui.write(b' ' * (16 - len(sname)))
+        ui.write(b' ' * (16 - len(name)))
         used = 16
         date = dateutil.makedate(mtime)
         age = b'(%s)' % templatefilters.age(date, abbrev=True)
         ui.write(age, label=b'shelve.age')
         ui.write(b' ' * (12 - len(age)))
         used += 12
-        with Shelf(repo, sname).open_patch() as fp:
+        with Shelf(repo, name).open_patch() as fp:
             while True:
                 line = fp.readline()
                 if not line:
@@ -701,8 +700,7 @@
         if not shelves:
             raise error.Abort(_(b"there are no shelves to show"))
         mtime, name = shelves[0]
-        sname = util.split(name)[1]
-        pats = [sname]
+        pats = [name]
 
     for shelfname in pats:
         if not Shelf(repo, shelfname).exists():
@@ -1122,7 +1120,7 @@
         shelved = listshelves(repo)
         if not shelved:
             raise error.StateError(_(b'no shelved changes to apply!'))
-        basename = util.split(shelved[0][1])[1]
+        basename = shelved[0][1]
         ui.status(_(b"unshelving change '%s'\n") % basename)
     else:
         basename = shelved[0]