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 (52 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 |
class shelvedfile(object): | class shelvedfile(object): | ||||
"""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.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)) | 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 | ||||
util.rename(self.filename(), self.backupfilename()) | util.rename(self.filename(), self.backupfilename()) | ||||
def stat(self): | def stat(self): | ||||
return self.vfs.stat(self.fname) | return self.vfs.stat(self.fname) | ||||
def opener(self, mode=b'rb'): | def opener(self, mode=b'rb'): | ||||
return self.vfs(self.fname, mode) | return self.vfs(self.fname, mode) | ||||
def applybundle(self, tr): | |||||
fp = self.opener() | |||||
try: | |||||
targetphase = phases.internal | |||||
if not phases.supportinternal(self.repo): | |||||
targetphase = phases.secret | |||||
gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs) | |||||
pretip = self.repo[b'tip'] | |||||
bundle2.applybundle( | |||||
self.repo, | |||||
gen, | |||||
tr, | |||||
source=b'unshelve', | |||||
url=b'bundle:' + self.vfs.join(self.fname), | |||||
targetphase=targetphase, | |||||
) | |||||
shelvectx = self.repo[b'tip'] | |||||
if pretip == shelvectx: | |||||
shelverev = tr.changes[b'revduplicates'][-1] | |||||
shelvectx = self.repo[shelverev] | |||||
return shelvectx | |||||
finally: | |||||
fp.close() | |||||
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. | ||||
""" | """ | ||||
self.repo.ui, | self.repo.ui, | ||||
cg, | cg, | ||||
bundle_filename, | bundle_filename, | ||||
btype, | btype, | ||||
self.vfs, | self.vfs, | ||||
compression=compression, | compression=compression, | ||||
) | ) | ||||
def applybundle(self, tr): | |||||
filename = self.name + b'.hg' | |||||
fp = self.vfs(filename) | |||||
try: | |||||
targetphase = phases.internal | |||||
if not phases.supportinternal(self.repo): | |||||
targetphase = phases.secret | |||||
gen = exchange.readbundle(self.repo.ui, fp, filename, self.vfs) | |||||
pretip = self.repo[b'tip'] | |||||
bundle2.applybundle( | |||||
self.repo, | |||||
gen, | |||||
tr, | |||||
source=b'unshelve', | |||||
url=b'bundle:' + self.vfs.join(filename), | |||||
targetphase=targetphase, | |||||
) | |||||
shelvectx = self.repo[b'tip'] | |||||
if pretip == shelvectx: | |||||
shelverev = tr.changes[b'revduplicates'][-1] | |||||
shelvectx = self.repo[shelverev] | |||||
return shelvectx | |||||
finally: | |||||
fp.close() | |||||
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. | ||||
""" | """ | ||||
def _unshelverestorecommit(ui, repo, tr, basename): | def _unshelverestorecommit(ui, repo, tr, basename): | ||||
"""Recreate commit in the repository during the unshelve""" | """Recreate commit in the repository during the unshelve""" | ||||
repo = repo.unfiltered() | repo = repo.unfiltered() | ||||
node = None | node = None | ||||
if shelvedfile(repo, basename, b'shelve').exists(): | if shelvedfile(repo, basename, b'shelve').exists(): | ||||
node = Shelf(repo, basename).readinfo()[b'node'] | node = Shelf(repo, basename).readinfo()[b'node'] | ||||
if node is None or node not in repo: | if node is None or node not in repo: | ||||
with ui.configoverride({(b'ui', b'quiet'): True}): | with ui.configoverride({(b'ui', b'quiet'): True}): | ||||
shelvectx = shelvedfile(repo, basename, b'hg').applybundle(tr) | shelvectx = Shelf(repo, basename).applybundle(tr) | ||||
# We might not strip the unbundled changeset, so we should keep track of | # We might not strip the unbundled changeset, so we should keep track of | ||||
# the unshelve node in case we need to reuse it (eg: unshelve --keep) | # the unshelve node in case we need to reuse it (eg: unshelve --keep) | ||||
if node is None: | if node is None: | ||||
info = {b'node': hex(shelvectx.node())} | info = {b'node': hex(shelvectx.node())} | ||||
Shelf(repo, basename).writeinfo(info) | Shelf(repo, basename).writeinfo(info) | ||||
else: | else: | ||||
shelvectx = repo[node] | shelvectx = repo[node] | ||||