Mercurial > hg
comparison mercurial/shelve.py @ 46292:3204a35e5c7e
shelve: make listshelves() list shelves in a given vfs
Differential Revision: https://phab.mercurial-scm.org/D9739
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 11 Jan 2021 23:02:20 -0800 |
parents | e2713c68b477 |
children | 9cdef4c41c94 |
comparison
equal
deleted
inserted
replaced
46291:e2713c68b477 | 46292:3204a35e5c7e |
---|---|
595 | 595 |
596 def cleanupcmd(ui, repo): | 596 def cleanupcmd(ui, repo): |
597 """subcommand that deletes all shelves""" | 597 """subcommand that deletes all shelves""" |
598 | 598 |
599 with repo.wlock(): | 599 with repo.wlock(): |
600 vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | |
600 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) | 601 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
601 for _mtime, name in listshelves(repo): | 602 for _mtime, name in listshelves(vfs): |
602 Shelf.open(repo, name).movetobackup(backupvfs) | 603 Shelf(vfs, name).movetobackup(backupvfs) |
603 cleanupoldbackups(repo) | 604 cleanupoldbackups(repo) |
604 | 605 |
605 | 606 |
606 def deletecmd(ui, repo, pats): | 607 def deletecmd(ui, repo, pats): |
607 """subcommand that deletes a specific shelve""" | 608 """subcommand that deletes a specific shelve""" |
617 ) | 618 ) |
618 shelf.movetobackup(backupvfs) | 619 shelf.movetobackup(backupvfs) |
619 cleanupoldbackups(repo) | 620 cleanupoldbackups(repo) |
620 | 621 |
621 | 622 |
622 def listshelves(repo): | 623 def listshelves(vfs): |
623 """return all shelves in repo as list of (time, name)""" | 624 """return all shelves in repo as list of (time, name)""" |
624 try: | 625 try: |
625 names = repo.vfs.listdir(shelvedir) | 626 names = vfs.listdir() |
626 except OSError as err: | 627 except OSError as err: |
627 if err.errno != errno.ENOENT: | 628 if err.errno != errno.ENOENT: |
628 raise | 629 raise |
629 return [] | 630 return [] |
630 info = [] | 631 info = [] |
632 for filename in names: | 633 for filename in names: |
633 name = filename.rsplit(b'.', 1)[0] | 634 name = filename.rsplit(b'.', 1)[0] |
634 if name in seen: | 635 if name in seen: |
635 continue | 636 continue |
636 seen.add(name) | 637 seen.add(name) |
637 shelf = Shelf.open(repo, name) | 638 shelf = Shelf(vfs, name) |
638 if not shelf.exists(): | 639 if not shelf.exists(): |
639 continue | 640 continue |
640 mtime = shelf.mtime() | 641 mtime = shelf.mtime() |
641 info.append((mtime, name)) | 642 info.append((mtime, name)) |
642 return sorted(info, reverse=True) | 643 return sorted(info, reverse=True) |
648 width = 80 | 649 width = 80 |
649 if not ui.plain(): | 650 if not ui.plain(): |
650 width = ui.termwidth() | 651 width = ui.termwidth() |
651 namelabel = b'shelve.newest' | 652 namelabel = b'shelve.newest' |
652 ui.pager(b'shelve') | 653 ui.pager(b'shelve') |
653 for mtime, name in listshelves(repo): | 654 vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
655 for mtime, name in listshelves(vfs): | |
654 if pats and name not in pats: | 656 if pats and name not in pats: |
655 continue | 657 continue |
656 ui.write(name, label=namelabel) | 658 ui.write(name, label=namelabel) |
657 namelabel = b'shelve.name' | 659 namelabel = b'shelve.name' |
658 if ui.quiet: | 660 if ui.quiet: |
689 | 691 |
690 | 692 |
691 def patchcmds(ui, repo, pats, opts): | 693 def patchcmds(ui, repo, pats, opts): |
692 """subcommand that displays shelves""" | 694 """subcommand that displays shelves""" |
693 if len(pats) == 0: | 695 if len(pats) == 0: |
694 shelves = listshelves(repo) | 696 vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
697 shelves = listshelves(vfs) | |
695 if not shelves: | 698 if not shelves: |
696 raise error.Abort(_(b"there are no shelves to show")) | 699 raise error.Abort(_(b"there are no shelves to show")) |
697 mtime, name = shelves[0] | 700 mtime, name = shelves[0] |
698 pats = [name] | 701 pats = [name] |
699 | 702 |
1109 elif continuef: | 1112 elif continuef: |
1110 return unshelvecontinue(ui, repo, state, opts) | 1113 return unshelvecontinue(ui, repo, state, opts) |
1111 elif len(shelved) > 1: | 1114 elif len(shelved) > 1: |
1112 raise error.InputError(_(b'can only unshelve one change at a time')) | 1115 raise error.InputError(_(b'can only unshelve one change at a time')) |
1113 elif not shelved: | 1116 elif not shelved: |
1114 shelved = listshelves(repo) | 1117 vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
1118 shelved = listshelves(vfs) | |
1115 if not shelved: | 1119 if not shelved: |
1116 raise error.StateError(_(b'no shelved changes to apply!')) | 1120 raise error.StateError(_(b'no shelved changes to apply!')) |
1117 basename = shelved[0][1] | 1121 basename = shelved[0][1] |
1118 ui.status(_(b"unshelving change '%s'\n") % basename) | 1122 ui.status(_(b"unshelving change '%s'\n") % basename) |
1119 else: | 1123 else: |