changeset 46289:c062874a35db

shelve: don't crash on file with unexpected extension in .hg/shelved/ We assumed that the files in the `.hg/shelved/` directory have an extension. That's a valid assumption except that users may put garbage in the directory. This patch fixes the crash by simply not assuming that the result of splittin a string at '.' yields an extension. We don't use the extension since the previous patch anyway. Differential Revision: https://phab.mercurial-scm.org/D9720
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 08 Jan 2021 23:08:37 -0800
parents 61f8fc12e167
children e33266b916be
files mercurial/shelve.py tests/test-shelve2.t
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/shelve.py	Mon Jan 11 09:26:48 2021 -0800
+++ b/mercurial/shelve.py	Fri Jan 08 23:08:37 2021 -0800
@@ -625,7 +625,7 @@
     info = []
     seen = set()
     for (filename, _type) in names:
-        name, ext = filename.rsplit(b'.', 1)
+        name = filename.rsplit(b'.', 1)[0]
         if name in seen:
             continue
         seen.add(name)
--- a/tests/test-shelve2.t	Mon Jan 11 09:26:48 2021 -0800
+++ b/tests/test-shelve2.t	Fri Jan 08 23:08:37 2021 -0800
@@ -779,10 +779,10 @@
 
 # A file with an unexpected extension
   $ touch .hg/shelved/junk3
-  $ hg shelve -l 2>&1 | grep ValueError
-  ValueError: * (glob)
-  $ hg unshelve 2>&1 | grep ValueError
-  ValueError: * (glob)
+  $ hg shelve -l
+  $ hg unshelve
+  abort: no shelved changes to apply!
+  [20]
   $ hg shelve -d junk3
   abort: shelved change 'junk3' not found
   [10]