Mercurial > hg-stable
comparison mercurial/shelve.py @ 46278:58ca94869287
shelve: move function for opening .patch file to new shelf class
The `opener()` method was used specifically for the `.patch` file, and
the new `Shelf` class deals with all files involved in a shelf, so I
renamed the function in the process.
Differential Revision: https://phab.mercurial-scm.org/D9705
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 07 Jan 2021 14:48:57 -0800 |
parents | ed2f2150d57c |
children | 14ce2eb6e8a4 |
comparison
equal
deleted
inserted
replaced
46277:ed2f2150d57c | 46278:58ca94869287 |
---|---|
112 util.rename(self.filename(), self.backupfilename()) | 112 util.rename(self.filename(), self.backupfilename()) |
113 | 113 |
114 def stat(self): | 114 def stat(self): |
115 return self.vfs.stat(self.fname) | 115 return self.vfs.stat(self.fname) |
116 | 116 |
117 def opener(self, mode=b'rb'): | |
118 return self.vfs(self.fname, mode) | |
119 | |
120 | 117 |
121 class Shelf(object): | 118 class Shelf(object): |
122 """Represents a shelf, including possibly multiple files storing it. | 119 """Represents a shelf, including possibly multiple files storing it. |
123 | 120 |
124 Old shelves will have a .patch and a .hg file. Newer shelves will | 121 Old shelves will have a .patch and a .hg file. Newer shelves will |
190 shelverev = tr.changes[b'revduplicates'][-1] | 187 shelverev = tr.changes[b'revduplicates'][-1] |
191 shelvectx = self.repo[shelverev] | 188 shelvectx = self.repo[shelverev] |
192 return shelvectx | 189 return shelvectx |
193 finally: | 190 finally: |
194 fp.close() | 191 fp.close() |
192 | |
193 def open_patch(self, mode=b'rb'): | |
194 return self.vfs(self.name + b'.patch', mode) | |
195 | 195 |
196 | 196 |
197 class shelvedstate(object): | 197 class shelvedstate(object): |
198 """Handle persistence during unshelving operations. | 198 """Handle persistence during unshelving operations. |
199 | 199 |
479 def _shelvecreatedcommit(repo, node, name, match): | 479 def _shelvecreatedcommit(repo, node, name, match): |
480 info = {b'node': hex(node)} | 480 info = {b'node': hex(node)} |
481 Shelf(repo, name).writeinfo(info) | 481 Shelf(repo, name).writeinfo(info) |
482 bases = list(mutableancestors(repo[node])) | 482 bases = list(mutableancestors(repo[node])) |
483 Shelf(repo, name).writebundle(bases, node) | 483 Shelf(repo, name).writebundle(bases, node) |
484 with shelvedfile(repo, name, patchextension).opener(b'wb') as fp: | 484 with Shelf(repo, name).open_patch(b'wb') as fp: |
485 cmdutil.exportfile( | 485 cmdutil.exportfile( |
486 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match | 486 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match |
487 ) | 487 ) |
488 | 488 |
489 | 489 |