# HG changeset patch # User Martin von Zweigbergk # Date 2021-01-08 07:18:24 # Node ID 3b08f56c8a111351a89c1ebcecb976a096b666a0 # Parent e79f8ae0901b4a53c0481a9bb304f5da498cc9f7 shelve: teach new shelf class to check if .shelve file exists This removes the only remaining use for `shelvedfile`, so the class now goes away. Differential Revision: https://phab.mercurial-scm.org/D9713 diff --git a/mercurial/shelve.py b/mercurial/shelve.py --- a/mercurial/shelve.py +++ b/mercurial/shelve.py @@ -72,24 +72,6 @@ patchextension = b'patch' 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): """Represents a shelf, including possibly multiple files storing it. @@ -113,6 +95,9 @@ class Shelf(object): def writeinfo(self, 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): return scmutil.simplekeyvaluefile( self.vfs, self.name + b'.shelve' @@ -890,7 +875,7 @@ def _unshelverestorecommit(ui, repo, tr, """Recreate commit in the repository during the unshelve""" repo = repo.unfiltered() node = None - if shelvedfile(repo, basename, b'shelve').exists(): + if Shelf(repo, basename).hasinfo(): node = Shelf(repo, basename).readinfo()[b'node'] if node is None or node not in repo: with ui.configoverride({(b'ui', b'quiet'): True}):