Mercurial > hg
changeset 46270:161313f9c467
shelve: rewrite check for unknown shelf to delete
The code would try to delete the shelf's .patch file and if that
raised an exception, it would convert it to an `error.Abort`. This
patch rewrites it so the check is done upfront. I find it easier to
read that way. It's now clear enough that I removed the comment
explaining it as well.
As Joerg pointed out during review, another differences is that the
old code would move a `.hg` file without its `.patch` friend to backup
before it realized that the `.patch` file was missing. The new code
will error out earlier and not move the `.hg` file, which seems like
an improvement. That should only matter on corrupt `.hg/shelved/`
directories, however.
Differential Revision: https://phab.mercurial-scm.org/D9697
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 07 Jan 2021 12:22:39 -0800 |
parents | 44556639f14a |
children | b2a8ff736ecf |
files | mercurial/shelve.py tests/test-shelve2.t |
diffstat | 2 files changed, 7 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/shelve.py Thu Jan 07 12:37:14 2021 -0800 +++ b/mercurial/shelve.py Thu Jan 07 12:22:39 2021 -0800 @@ -600,20 +600,12 @@ raise error.Abort(_(b'no shelved changes specified!')) with repo.wlock(): for name in pats: - try: - for suffix in shelvefileextensions: - shfile = shelvedfile(repo, name, suffix) - # patch file is necessary, as it should - # be present for any kind of shelve, - # but the .hg file is optional as in future we - # will add obsolete shelve with does not create a - # bundle - if shfile.exists() or suffix == patchextension: - shfile.movetobackup() - except OSError as err: - if err.errno != errno.ENOENT: - raise + if not shelvedfile(repo, name, patchextension).exists(): raise error.Abort(_(b"shelved change '%s' not found") % name) + for suffix in shelvefileextensions: + shfile = shelvedfile(repo, name, suffix) + if shfile.exists(): + shfile.movetobackup() cleanupoldbackups(repo)
--- a/tests/test-shelve2.t Thu Jan 07 12:37:14 2021 -0800 +++ b/tests/test-shelve2.t Thu Jan 07 12:22:39 2021 -0800 @@ -776,8 +776,8 @@ $ find .hg/shelve* | sort .hg/shelve-backup .hg/shelve-backup/junk1.patch - .hg/shelve-backup/junk2.hg .hg/shelved + .hg/shelved/junk2.hg # A file with an unexpected extension $ touch .hg/shelved/junk3 @@ -791,8 +791,8 @@ $ find .hg/shelve* | sort .hg/shelve-backup .hg/shelve-backup/junk1.patch - .hg/shelve-backup/junk2.hg .hg/shelved + .hg/shelved/junk2.hg .hg/shelved/junk3 $ cd ..