232 success). |
232 success). |
233 """ |
233 """ |
234 self._addbackupentry(('', '', tmpfile, False)) |
234 self._addbackupentry(('', '', tmpfile, False)) |
235 |
235 |
236 @active |
236 @active |
237 def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None): |
237 def addfilegenerator(self, genid, filenames, genfunc, order=0, |
|
238 location=''): |
238 """add a function to generates some files at transaction commit |
239 """add a function to generates some files at transaction commit |
239 |
240 |
240 The `genfunc` argument is a function capable of generating proper |
241 The `genfunc` argument is a function capable of generating proper |
241 content of each entry in the `filename` tuple. |
242 content of each entry in the `filename` tuple. |
242 |
243 |
250 generated once. Call to `addfilegenerator` for a `genid` already |
251 generated once. Call to `addfilegenerator` for a `genid` already |
251 present will overwrite the old entry. |
252 present will overwrite the old entry. |
252 |
253 |
253 The `order` argument may be used to control the order in which multiple |
254 The `order` argument may be used to control the order in which multiple |
254 generator will be executed. |
255 generator will be executed. |
|
256 |
|
257 The `location` arguments may be used to indicate the files are located |
|
258 outside of the the standard directory for transaction. It should match |
|
259 one of the key of the `transaction.vfsmap` dictionnary. |
255 """ |
260 """ |
256 # 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 |
257 # but for bookmarks that are handled outside this mechanism. |
262 # but for bookmarks that are handled outside this mechanism. |
258 assert vfs is None or filenames == ('bookmarks',) |
263 self._filegenerators[genid] = (order, filenames, genfunc, location) |
259 self._filegenerators[genid] = (order, filenames, genfunc, vfs) |
|
260 |
264 |
261 def _generatefiles(self): |
265 def _generatefiles(self): |
262 # write files registered for generation |
266 # write files registered for generation |
263 for entry in sorted(self._filegenerators.values()): |
267 for entry in sorted(self._filegenerators.values()): |
264 order, filenames, genfunc, vfs = entry |
268 order, filenames, genfunc, location = entry |
265 if vfs is None: |
269 vfs = self._vfsmap[location] |
266 vfs = self.opener |
|
267 files = [] |
270 files = [] |
268 try: |
271 try: |
269 for name in filenames: |
272 for name in filenames: |
270 # Some files are already backed up when creating the |
273 # Some files are already backed up when creating the |
271 # localrepo. Until this is properly fixed we disable the |
274 # localrepo. Until this is properly fixed we disable the |
272 # backup for them. |
275 # backup for them. |
273 if name not in ('phaseroots', 'bookmarks'): |
276 if name not in ('phaseroots', 'bookmarks'): |
274 self.addbackup(name) |
277 self.addbackup(name, location=location) |
275 files.append(vfs(name, 'w', atomictemp=True)) |
278 files.append(vfs(name, 'w', atomictemp=True)) |
276 genfunc(*files) |
279 genfunc(*files) |
277 finally: |
280 finally: |
278 for f in files: |
281 for f in files: |
279 f.close() |
282 f.close() |