Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/shelve.py (20 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
16b4b59de705 | 5a9c9b0ffc15 | Martin von Zweigbergk | Jan 12 2021, 2:02 AM |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz |
def _iswctxonnewbranch(repo): | def _iswctxonnewbranch(repo): | ||||
return repo[None].branch() != repo[b'.'].branch() | return repo[None].branch() != repo[b'.'].branch() | ||||
def cleanupcmd(ui, repo): | def cleanupcmd(ui, repo): | ||||
"""subcommand that deletes all shelves""" | """subcommand that deletes all shelves""" | ||||
with repo.wlock(): | with repo.wlock(): | ||||
vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | |||||
backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) | backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) | ||||
for _mtime, name in listshelves(repo): | for _mtime, name in listshelves(vfs): | ||||
Shelf.open(repo, name).movetobackup(backupvfs) | Shelf(vfs, name).movetobackup(backupvfs) | ||||
cleanupoldbackups(repo) | cleanupoldbackups(repo) | ||||
def deletecmd(ui, repo, pats): | def deletecmd(ui, repo, pats): | ||||
"""subcommand that deletes a specific shelve""" | """subcommand that deletes a specific shelve""" | ||||
if not pats: | if not pats: | ||||
raise error.InputError(_(b'no shelved changes specified!')) | raise error.InputError(_(b'no shelved changes specified!')) | ||||
with repo.wlock(): | with repo.wlock(): | ||||
backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) | backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) | ||||
for name in pats: | for name in pats: | ||||
shelf = Shelf.open(repo, name) | shelf = Shelf.open(repo, name) | ||||
if not shelf.exists(): | if not shelf.exists(): | ||||
raise error.InputError( | raise error.InputError( | ||||
_(b"shelved change '%s' not found") % name | _(b"shelved change '%s' not found") % name | ||||
) | ) | ||||
shelf.movetobackup(backupvfs) | shelf.movetobackup(backupvfs) | ||||
cleanupoldbackups(repo) | cleanupoldbackups(repo) | ||||
def listshelves(repo): | def listshelves(vfs): | ||||
"""return all shelves in repo as list of (time, name)""" | """return all shelves in repo as list of (time, name)""" | ||||
try: | try: | ||||
names = repo.vfs.listdir(shelvedir) | names = vfs.listdir() | ||||
except OSError as err: | except OSError as err: | ||||
if err.errno != errno.ENOENT: | if err.errno != errno.ENOENT: | ||||
raise | raise | ||||
return [] | return [] | ||||
info = [] | info = [] | ||||
seen = set() | seen = set() | ||||
for filename in names: | for filename in names: | ||||
name = filename.rsplit(b'.', 1)[0] | name = filename.rsplit(b'.', 1)[0] | ||||
if name in seen: | if name in seen: | ||||
continue | continue | ||||
seen.add(name) | seen.add(name) | ||||
shelf = Shelf.open(repo, name) | shelf = Shelf(vfs, name) | ||||
if not shelf.exists(): | if not shelf.exists(): | ||||
continue | continue | ||||
mtime = shelf.mtime() | mtime = shelf.mtime() | ||||
info.append((mtime, name)) | info.append((mtime, name)) | ||||
return sorted(info, reverse=True) | return sorted(info, reverse=True) | ||||
def listcmd(ui, repo, pats, opts): | def listcmd(ui, repo, pats, opts): | ||||
"""subcommand that displays the list of shelves""" | """subcommand that displays the list of shelves""" | ||||
pats = set(pats) | pats = set(pats) | ||||
width = 80 | width = 80 | ||||
if not ui.plain(): | if not ui.plain(): | ||||
width = ui.termwidth() | width = ui.termwidth() | ||||
namelabel = b'shelve.newest' | namelabel = b'shelve.newest' | ||||
ui.pager(b'shelve') | ui.pager(b'shelve') | ||||
for mtime, name in listshelves(repo): | vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | ||||
for mtime, name in listshelves(vfs): | |||||
if pats and name not in pats: | if pats and name not in pats: | ||||
continue | continue | ||||
ui.write(name, label=namelabel) | ui.write(name, label=namelabel) | ||||
namelabel = b'shelve.name' | namelabel = b'shelve.name' | ||||
if ui.quiet: | if ui.quiet: | ||||
ui.write(b'\n') | ui.write(b'\n') | ||||
continue | continue | ||||
ui.write(b' ' * (16 - len(name))) | ui.write(b' ' * (16 - len(name))) | ||||
if opts[b'stat']: | if opts[b'stat']: | ||||
for chunk, label in patch.diffstatui(difflines, width=width): | for chunk, label in patch.diffstatui(difflines, width=width): | ||||
ui.write(chunk, label=label) | ui.write(chunk, label=label) | ||||
def patchcmds(ui, repo, pats, opts): | def patchcmds(ui, repo, pats, opts): | ||||
"""subcommand that displays shelves""" | """subcommand that displays shelves""" | ||||
if len(pats) == 0: | if len(pats) == 0: | ||||
shelves = listshelves(repo) | vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | ||||
shelves = listshelves(vfs) | |||||
if not shelves: | if not shelves: | ||||
raise error.Abort(_(b"there are no shelves to show")) | raise error.Abort(_(b"there are no shelves to show")) | ||||
mtime, name = shelves[0] | mtime, name = shelves[0] | ||||
pats = [name] | pats = [name] | ||||
for shelfname in pats: | for shelfname in pats: | ||||
if not Shelf.open(repo, shelfname).exists(): | if not Shelf.open(repo, shelfname).exists(): | ||||
raise error.Abort(_(b"cannot find shelf %s") % shelfname) | raise error.Abort(_(b"cannot find shelf %s") % shelfname) | ||||
raise error.InputError( | raise error.InputError( | ||||
_(b'cannot use both continue and interactive') | _(b'cannot use both continue and interactive') | ||||
) | ) | ||||
elif continuef: | elif continuef: | ||||
return unshelvecontinue(ui, repo, state, opts) | return unshelvecontinue(ui, repo, state, opts) | ||||
elif len(shelved) > 1: | elif len(shelved) > 1: | ||||
raise error.InputError(_(b'can only unshelve one change at a time')) | raise error.InputError(_(b'can only unshelve one change at a time')) | ||||
elif not shelved: | elif not shelved: | ||||
shelved = listshelves(repo) | vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | ||||
shelved = listshelves(vfs) | |||||
if not shelved: | if not shelved: | ||||
raise error.StateError(_(b'no shelved changes to apply!')) | raise error.StateError(_(b'no shelved changes to apply!')) | ||||
basename = shelved[0][1] | basename = shelved[0][1] | ||||
ui.status(_(b"unshelving change '%s'\n") % basename) | ui.status(_(b"unshelving change '%s'\n") % basename) | ||||
else: | else: | ||||
basename = shelved[0] | basename = shelved[0] | ||||
if not Shelf.open(repo, basename).exists(): | if not Shelf.open(repo, basename).exists(): |