Mercurial > hg
comparison mercurial/shelve.py @ 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 |
comparison
equal
deleted
inserted
replaced
46269:44556639f14a | 46270:161313f9c467 |
---|---|
598 """subcommand that deletes a specific shelve""" | 598 """subcommand that deletes a specific shelve""" |
599 if not pats: | 599 if not pats: |
600 raise error.Abort(_(b'no shelved changes specified!')) | 600 raise error.Abort(_(b'no shelved changes specified!')) |
601 with repo.wlock(): | 601 with repo.wlock(): |
602 for name in pats: | 602 for name in pats: |
603 try: | 603 if not shelvedfile(repo, name, patchextension).exists(): |
604 for suffix in shelvefileextensions: | |
605 shfile = shelvedfile(repo, name, suffix) | |
606 # patch file is necessary, as it should | |
607 # be present for any kind of shelve, | |
608 # but the .hg file is optional as in future we | |
609 # will add obsolete shelve with does not create a | |
610 # bundle | |
611 if shfile.exists() or suffix == patchextension: | |
612 shfile.movetobackup() | |
613 except OSError as err: | |
614 if err.errno != errno.ENOENT: | |
615 raise | |
616 raise error.Abort(_(b"shelved change '%s' not found") % name) | 604 raise error.Abort(_(b"shelved change '%s' not found") % name) |
605 for suffix in shelvefileextensions: | |
606 shfile = shelvedfile(repo, name, suffix) | |
607 if shfile.exists(): | |
608 shfile.movetobackup() | |
617 cleanupoldbackups(repo) | 609 cleanupoldbackups(repo) |
618 | 610 |
619 | 611 |
620 def listshelves(repo): | 612 def listshelves(repo): |
621 """return all shelves in repo as list of (time, filename)""" | 613 """return all shelves in repo as list of (time, filename)""" |