Mercurial > hg
comparison mercurial/transaction.py @ 23356:140c21fbf4eb
transaction: allow generating files with a suffix
This will allow us to generate temporary pending files. Files
generated with a suffix are assumed temporary and will be cleaned up
at the end of the transaction.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 29 Sep 2014 01:29:08 -0700 |
parents | 7faa55c20b0e |
children | ba033f461f00 |
comparison
equal
deleted
inserted
replaced
23355:7faa55c20b0e | 23356:140c21fbf4eb |
---|---|
260 """ | 260 """ |
261 # For now, we are unable to do proper backup and restore of custom vfs | 261 # For now, we are unable to do proper backup and restore of custom vfs |
262 # but for bookmarks that are handled outside this mechanism. | 262 # but for bookmarks that are handled outside this mechanism. |
263 self._filegenerators[genid] = (order, filenames, genfunc, location) | 263 self._filegenerators[genid] = (order, filenames, genfunc, location) |
264 | 264 |
265 def _generatefiles(self): | 265 def _generatefiles(self, suffix=''): |
266 # write files registered for generation | 266 # write files registered for generation |
267 for entry in sorted(self._filegenerators.values()): | 267 for entry in sorted(self._filegenerators.values()): |
268 order, filenames, genfunc, location = entry | 268 order, filenames, genfunc, location = entry |
269 vfs = self._vfsmap[location] | 269 vfs = self._vfsmap[location] |
270 files = [] | 270 files = [] |
271 try: | 271 try: |
272 for name in filenames: | 272 for name in filenames: |
273 self.addbackup(name, location=location) | 273 name += suffix |
274 if suffix: | |
275 self.registertmp(name, location=location) | |
276 else: | |
277 self.addbackup(name, location=location) | |
274 files.append(vfs(name, 'w', atomictemp=True)) | 278 files.append(vfs(name, 'w', atomictemp=True)) |
275 genfunc(*files) | 279 genfunc(*files) |
276 finally: | 280 finally: |
277 for f in files: | 281 for f in files: |
278 f.close() | 282 f.close() |