Mercurial > hg
comparison mercurial/shelve.py @ 46275:157305bf859f
shelve: move method for reading .shelve file to new shelf class
Differential Revision: https://phab.mercurial-scm.org/D9702
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 07 Jan 2021 11:28:41 -0800 |
parents | a344ec05b99c |
children | eb7b2929ae49 |
comparison
equal
deleted
inserted
replaced
46274:a344ec05b99c | 46275:157305bf859f |
---|---|
161 | 161 |
162 bundle2.writebundle( | 162 bundle2.writebundle( |
163 self.ui, cg, self.fname, btype, self.vfs, compression=compression | 163 self.ui, cg, self.fname, btype, self.vfs, compression=compression |
164 ) | 164 ) |
165 | 165 |
166 def readinfo(self): | |
167 return scmutil.simplekeyvaluefile(self.vfs, self.fname).read() | |
168 | |
169 | 166 |
170 class Shelf(object): | 167 class Shelf(object): |
171 """Represents a shelf, including possibly multiple files storing it. | 168 """Represents a shelf, including possibly multiple files storing it. |
172 | 169 |
173 Old shelves will have a .patch and a .hg file. Newer shelves will | 170 Old shelves will have a .patch and a .hg file. Newer shelves will |
183 def exists(self): | 180 def exists(self): |
184 return self.vfs.exists(self.name + b'.' + patchextension) | 181 return self.vfs.exists(self.name + b'.' + patchextension) |
185 | 182 |
186 def writeinfo(self, info): | 183 def writeinfo(self, info): |
187 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) | 184 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) |
185 | |
186 def readinfo(self): | |
187 return scmutil.simplekeyvaluefile( | |
188 self.vfs, self.name + b'.shelve' | |
189 ).read() | |
188 | 190 |
189 | 191 |
190 class shelvedstate(object): | 192 class shelvedstate(object): |
191 """Handle persistence during unshelving operations. | 193 """Handle persistence during unshelving operations. |
192 | 194 |
892 def _unshelverestorecommit(ui, repo, tr, basename): | 894 def _unshelverestorecommit(ui, repo, tr, basename): |
893 """Recreate commit in the repository during the unshelve""" | 895 """Recreate commit in the repository during the unshelve""" |
894 repo = repo.unfiltered() | 896 repo = repo.unfiltered() |
895 node = None | 897 node = None |
896 if shelvedfile(repo, basename, b'shelve').exists(): | 898 if shelvedfile(repo, basename, b'shelve').exists(): |
897 node = shelvedfile(repo, basename, b'shelve').readinfo()[b'node'] | 899 node = Shelf(repo, basename).readinfo()[b'node'] |
898 if node is None or node not in repo: | 900 if node is None or node not in repo: |
899 with ui.configoverride({(b'ui', b'quiet'): True}): | 901 with ui.configoverride({(b'ui', b'quiet'): True}): |
900 shelvectx = shelvedfile(repo, basename, b'hg').applybundle(tr) | 902 shelvectx = shelvedfile(repo, basename, b'hg').applybundle(tr) |
901 # We might not strip the unbundled changeset, so we should keep track of | 903 # We might not strip the unbundled changeset, so we should keep track of |
902 # the unshelve node in case we need to reuse it (eg: unshelve --keep) | 904 # the unshelve node in case we need to reuse it (eg: unshelve --keep) |