changeset 23317:197e17be5407

transaction: use 'location' instead of 'vfs' objects for file generation The argument is now a location name. The location must be present in the 'vfsmap' provided to the transaction at creation time.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 17 Oct 2014 20:53:42 -0700
parents fc3670f41d3e
children fc73293f6060
files mercurial/bookmarks.py mercurial/transaction.py
diffstat 2 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Wed Nov 05 01:59:32 2014 +0000
+++ b/mercurial/bookmarks.py	Fri Oct 17 20:53:42 2014 -0700
@@ -52,7 +52,7 @@
 
         The transaction is then responsible for updating the file content."""
         tr.addfilegenerator('bookmarks', ('bookmarks',), self._write,
-                            vfs=self._repo.vfs)
+                            location='plain')
         tr.hookargs['bookmark_moved'] = '1'
 
     def write(self):
--- a/mercurial/transaction.py	Wed Nov 05 01:59:32 2014 +0000
+++ b/mercurial/transaction.py	Fri Oct 17 20:53:42 2014 -0700
@@ -234,7 +234,8 @@
         self._addbackupentry(('', '', tmpfile, False))
 
     @active
-    def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None):
+    def addfilegenerator(self, genid, filenames, genfunc, order=0,
+                         location=''):
         """add a function to generates some files at transaction commit
 
         The `genfunc` argument is a function capable of generating proper
@@ -252,18 +253,20 @@
 
         The `order` argument may be used to control the order in which multiple
         generator will be executed.
+
+        The `location` arguments may be used to indicate the files are located
+        outside of the the standard directory for transaction. It should match
+        one of the key of the `transaction.vfsmap` dictionnary.
         """
         # For now, we are unable to do proper backup and restore of custom vfs
         # but for bookmarks that are handled outside this mechanism.
-        assert vfs is None or filenames == ('bookmarks',)
-        self._filegenerators[genid] = (order, filenames, genfunc, vfs)
+        self._filegenerators[genid] = (order, filenames, genfunc, location)
 
     def _generatefiles(self):
         # write files registered for generation
         for entry in sorted(self._filegenerators.values()):
-            order, filenames, genfunc, vfs = entry
-            if vfs is None:
-                vfs = self.opener
+            order, filenames, genfunc, location = entry
+            vfs = self._vfsmap[location]
             files = []
             try:
                 for name in filenames:
@@ -271,7 +274,7 @@
                     # localrepo. Until this is properly fixed we disable the
                     # backup for them.
                     if name not in ('phaseroots', 'bookmarks'):
-                        self.addbackup(name)
+                        self.addbackup(name, location=location)
                     files.append(vfs(name, 'w', atomictemp=True))
                 genfunc(*files)
             finally: