Patchwork [4,of,5,main-line-of-work,(12,more,to,go)] transaction: use 'location' instead of 'vfs' objects for file generation

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 14, 2014, 6:58 p.m.
Message ID <9a474e2e2129056029cf.1415991504@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6738/
State Accepted
Commit 197e17be540715c6bc94e1c360d0a421a63d4e7f
Headers show

Comments

Pierre-Yves David - Nov. 14, 2014, 6:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1413604422 25200
#      Fri Oct 17 20:53:42 2014 -0700
# Node ID 9a474e2e2129056029cf196c1935769344fce855
# Parent  4b298cf2b57eb36d8434220221630ed833ad1a0e
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.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -50,11 +50,11 @@  class bmstore(dict):
     def recordchange(self, tr):
         """record that bookmarks have been changed in a transaction
 
         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):
         '''Write bookmarks
 
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -232,11 +232,12 @@  class transaction(object):
         success).
         """
         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
         content of each entry in the `filename` tuple.
 
@@ -250,30 +251,32 @@  class transaction(object):
         generated once. Call to `addfilegenerator` for a `genid` already
         present will overwrite the old entry.
 
         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:
                     # Some files are already backed up when creating the
                     # 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:
                 for f in files:
                     f.close()