This removes the only remaining use for shelvedfile, so the class
now goes away.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
This removes the only remaining use for shelvedfile, so the class
now goes away.
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/shelve.py (23 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
0620d9791932 | 764d1b04f2e5 | Martin von Zweigbergk | Jan 8 2021, 2:18 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 |
# universal extension is present in all types of shelves | # universal extension is present in all types of shelves | ||||
patchextension = b'patch' | patchextension = b'patch' | ||||
# we never need the user, so we use a | # we never need the user, so we use a | ||||
# generic user for all shelve operations | # generic user for all shelve operations | ||||
shelveuser = b'shelve@localhost' | shelveuser = b'shelve@localhost' | ||||
class shelvedfile(object): | |||||
"""Helper for the file storing a single shelve | |||||
Handles common functions on shelve files (.hg/.patch) using | |||||
the vfs layer""" | |||||
def __init__(self, repo, name, filetype=None): | |||||
self.name = name | |||||
self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | |||||
if filetype: | |||||
self.fname = name + b'.' + filetype | |||||
else: | |||||
self.fname = name | |||||
def exists(self): | |||||
return self.vfs.exists(self.fname) | |||||
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)) | 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): | ||||
scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) | scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) | ||||
def hasinfo(self): | |||||
return self.vfs.exists(self.name + b'.shelve') | |||||
def readinfo(self): | def readinfo(self): | ||||
return scmutil.simplekeyvaluefile( | return scmutil.simplekeyvaluefile( | ||||
self.vfs, self.name + b'.shelve' | self.vfs, self.name + b'.shelve' | ||||
).read() | ).read() | ||||
def writebundle(self, bases, node): | def writebundle(self, bases, node): | ||||
cgversion = changegroup.safeversion(self.repo) | cgversion = changegroup.safeversion(self.repo) | ||||
if cgversion == b'01': | if cgversion == b'01': | ||||
tmpwctx = repo[node] | tmpwctx = repo[node] | ||||
return tmpwctx, addedbefore | return tmpwctx, addedbefore | ||||
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 Shelf(repo, basename).hasinfo(): | ||||
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 = Shelf(repo, basename).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())} |