Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/shelve.py @ 46286:3b08f56c8a11
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 07 Jan 2021 23:18:24 -0800 |
parents | e79f8ae0901b |
children | ae7a77a7ebc0 |
comparison
equal
deleted
inserted
replaced
46285:e79f8ae0901b | 46286:3b08f56c8a11 |
---|---|
70 # we never need the user, so we use a | 70 # we never need the user, so we use a |
71 # generic user for all shelve operations | 71 # generic user for all shelve operations |
72 shelveuser = b'shelve@localhost' | 72 shelveuser = b'shelve@localhost' |
73 | 73 |
74 | 74 |
75 class shelvedfile(object): | |
76 """Helper for the file storing a single shelve | |
77 | |
78 Handles common functions on shelve files (.hg/.patch) using | |
79 the vfs layer""" | |
80 | |
81 def __init__(self, repo, name, filetype=None): | |
82 self.name = name | |
83 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | |
84 if filetype: | |
85 self.fname = name + b'.' + filetype | |
86 else: | |
87 self.fname = name | |
88 | |
89 def exists(self): | |
90 return self.vfs.exists(self.fname) | |
91 | |
92 | |
93 class Shelf(object): | 75 class Shelf(object): |
94 """Represents a shelf, including possibly multiple files storing it. | 76 """Represents a shelf, including possibly multiple files storing it. |
95 | 77 |
96 Old shelves will have a .patch and a .hg file. Newer shelves will | 78 Old shelves will have a .patch and a .hg file. Newer shelves will |
97 also have a .shelve file. This class abstracts away some of the | 79 also have a .shelve file. This class abstracts away some of the |
110 def mtime(self): | 92 def mtime(self): |
111 return self.vfs.stat(self.name + b'.' + patchextension)[stat.ST_MTIME] | 93 return self.vfs.stat(self.name + b'.' + patchextension)[stat.ST_MTIME] |
112 | 94 |
113 def writeinfo(self, info): | 95 def writeinfo(self, info): |
114 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) | 96 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) |
97 | |
98 def hasinfo(self): | |
99 return self.vfs.exists(self.name + b'.shelve') | |
115 | 100 |
116 def readinfo(self): | 101 def readinfo(self): |
117 return scmutil.simplekeyvaluefile( | 102 return scmutil.simplekeyvaluefile( |
118 self.vfs, self.name + b'.shelve' | 103 self.vfs, self.name + b'.shelve' |
119 ).read() | 104 ).read() |
888 | 873 |
889 def _unshelverestorecommit(ui, repo, tr, basename): | 874 def _unshelverestorecommit(ui, repo, tr, basename): |
890 """Recreate commit in the repository during the unshelve""" | 875 """Recreate commit in the repository during the unshelve""" |
891 repo = repo.unfiltered() | 876 repo = repo.unfiltered() |
892 node = None | 877 node = None |
893 if shelvedfile(repo, basename, b'shelve').exists(): | 878 if Shelf(repo, basename).hasinfo(): |
894 node = Shelf(repo, basename).readinfo()[b'node'] | 879 node = Shelf(repo, basename).readinfo()[b'node'] |
895 if node is None or node not in repo: | 880 if node is None or node not in repo: |
896 with ui.configoverride({(b'ui', b'quiet'): True}): | 881 with ui.configoverride({(b'ui', b'quiet'): True}): |
897 shelvectx = Shelf(repo, basename).applybundle(tr) | 882 shelvectx = Shelf(repo, basename).applybundle(tr) |
898 # We might not strip the unbundled changeset, so we should keep track of | 883 # We might not strip the unbundled changeset, so we should keep track of |