Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/shelve.py (54 lines) |
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 |
"""Helper for the file storing a single shelve | """Helper for the file storing a single shelve | ||||
Handles common functions on shelve files (.hg/.patch) using | Handles common functions on shelve files (.hg/.patch) using | ||||
the vfs layer""" | the vfs layer""" | ||||
def __init__(self, repo, name, filetype=None): | def __init__(self, repo, name, filetype=None): | ||||
self.name = name | self.name = name | ||||
self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | ||||
self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) | |||||
if filetype: | if filetype: | ||||
self.fname = name + b'.' + filetype | self.fname = name + b'.' + filetype | ||||
else: | else: | ||||
self.fname = name | self.fname = name | ||||
def exists(self): | def exists(self): | ||||
return self.vfs.exists(self.fname) | return self.vfs.exists(self.fname) | ||||
def backupfilename(self): | |||||
def gennames(base): | |||||
yield base | |||||
base, ext = base.rsplit(b'.', 1) | |||||
for i in itertools.count(1): | |||||
yield b'%s-%d.%s' % (base, i, ext) | |||||
for n in gennames(self.fname): | |||||
if not self.backupvfs.exists(n): | |||||
return self.backupvfs.join(n) | |||||
def movetobackup(self): | |||||
if not self.backupvfs.isdir(): | |||||
self.backupvfs.makedir() | |||||
util.rename(self.vfs.join(self.fname), self.backupfilename()) | |||||
class Shelf(object): | class Shelf(object): | ||||
"""Represents a shelf, including possibly multiple files storing it. | """Represents a shelf, including possibly multiple files storing it. | ||||
Old shelves will have a .patch and a .hg file. Newer shelves will | Old shelves will have a .patch and a .hg file. Newer shelves will | ||||
also have a .shelve file. This class abstracts away some of the | also have a .shelve file. This class abstracts away some of the | ||||
differences and lets you work with the shelf as a whole. | differences and lets you work with the shelf as a whole. | ||||
""" | """ | ||||
def __init__(self, repo, name): | def __init__(self, repo, name): | ||||
self.repo = repo | self.repo = repo | ||||
self.name = name | self.name = name | ||||
self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | ||||
self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) | |||||
def exists(self): | def exists(self): | ||||
return self.vfs.exists(self.name + b'.' + patchextension) | return self.vfs.exists(self.name + b'.' + patchextension) | ||||
def mtime(self): | def mtime(self): | ||||
return self.vfs.stat(self.name + b'.' + patchextension)[stat.ST_MTIME] | return self.vfs.stat(self.name + b'.' + patchextension)[stat.ST_MTIME] | ||||
def writeinfo(self, info): | def writeinfo(self, info): | ||||
shelvectx = self.repo[shelverev] | shelvectx = self.repo[shelverev] | ||||
return shelvectx | return shelvectx | ||||
finally: | finally: | ||||
fp.close() | fp.close() | ||||
def open_patch(self, mode=b'rb'): | def open_patch(self, mode=b'rb'): | ||||
return self.vfs(self.name + b'.patch', mode) | return self.vfs(self.name + b'.patch', mode) | ||||
def _backupfilename(self, filename): | |||||
def gennames(base): | |||||
yield base | |||||
base, ext = base.rsplit(b'.', 1) | |||||
for i in itertools.count(1): | |||||
yield b'%s-%d.%s' % (base, i, ext) | |||||
for n in gennames(filename): | |||||
if not self.backupvfs.exists(n): | |||||
return self.backupvfs.join(n) | |||||
def movetobackup(self): | |||||
if not self.backupvfs.isdir(): | |||||
self.backupvfs.makedir() | |||||
for suffix in shelvefileextensions: | |||||
filename = self.name + b'.' + suffix | |||||
if self.vfs.exists(filename): | |||||
util.rename( | |||||
self.vfs.join(filename), self._backupfilename(filename) | |||||
) | |||||
class shelvedstate(object): | class shelvedstate(object): | ||||
"""Handle persistence during unshelving operations. | """Handle persistence during unshelving operations. | ||||
Handles saving and restoring a shelved state. Ensures that different | Handles saving and restoring a shelved state. Ensures that different | ||||
versions of a shelved state are possible and handles them appropriately. | versions of a shelved state are possible and handles them appropriately. | ||||
""" | """ | ||||
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(): | ||||
for _mtime, name in listshelves(repo): | for _mtime, name in listshelves(repo): | ||||
for suffix in shelvefileextensions: | Shelf(repo, name).movetobackup() | ||||
shfile = shelvedfile(repo, name, suffix) | |||||
if shfile.exists(): | |||||
shfile.movetobackup() | |||||
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(): | ||||
for name in pats: | for name in pats: | ||||
if not Shelf(repo, name).exists(): | if not Shelf(repo, name).exists(): | ||||
raise error.InputError( | raise error.InputError( | ||||
_(b"shelved change '%s' not found") % name | _(b"shelved change '%s' not found") % name | ||||
) | ) | ||||
for suffix in shelvefileextensions: | Shelf(repo, name).movetobackup() | ||||
shfile = shelvedfile(repo, name, suffix) | |||||
if shfile.exists(): | |||||
shfile.movetobackup() | |||||
cleanupoldbackups(repo) | cleanupoldbackups(repo) | ||||
def listshelves(repo): | def listshelves(repo): | ||||
"""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.readdir(shelvedir) | names = repo.vfs.readdir(shelvedir) | ||||
except OSError as err: | except OSError as err: | ||||
ui.status( | ui.status( | ||||
_(b'marked working directory as branch %s\n') % branchtorestore | _(b'marked working directory as branch %s\n') % branchtorestore | ||||
) | ) | ||||
def unshelvecleanup(ui, repo, name, opts): | def unshelvecleanup(ui, repo, name, opts): | ||||
"""remove related files after an unshelve""" | """remove related files after an unshelve""" | ||||
if not opts.get(b'keep'): | if not opts.get(b'keep'): | ||||
for filetype in shelvefileextensions: | Shelf(repo, name).movetobackup() | ||||
shfile = shelvedfile(repo, name, filetype) | |||||
if shfile.exists(): | |||||
shfile.movetobackup() | |||||
cleanupoldbackups(repo) | cleanupoldbackups(repo) | ||||
def unshelvecontinue(ui, repo, state, opts): | def unshelvecontinue(ui, repo, state, opts): | ||||
"""subcommand to continue an in-progress unshelve""" | """subcommand to continue an in-progress unshelve""" | ||||
# We're finishing off a merge. First parent is our original | # We're finishing off a merge. First parent is our original | ||||
# parent, second is the temporary "fake" commit we're unshelving. | # parent, second is the temporary "fake" commit we're unshelving. | ||||
interactive = state.interactive | interactive = state.interactive |