transaction: pass a vfs map to the transaction
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 17 Oct 2014 20:49:39 -0700
changeset 23310 5bd1f6572db0
parent 23309 7eb520f5efe4
child 23311 64ab33ffba14
transaction: pass a vfs map to the transaction The goal is to allow access to file outside ofthe store directory from the transaction. The obvious target are the `bookmarks` file. But we can envision usage for cache too. We keep passing a main opener explicitly because a lot of code rely on this default opener. The main opener (operating on store) is using an empty key ''.
contrib/undumprevlog
mercurial/localrepo.py
mercurial/transaction.py
--- a/contrib/undumprevlog	Wed Nov 05 01:52:46 2014 +0000
+++ b/contrib/undumprevlog	Fri Oct 17 20:49:39 2014 -0700
@@ -10,7 +10,8 @@
     util.setbinary(fp)
 
 opener = scmutil.opener('.', False)
-tr = transaction.transaction(sys.stderr.write, opener, "undump.journal")
+tr = transaction.transaction(sys.stderr.write, opener, {'store': opener},
+                             "undump.journal")
 while True:
     l = sys.stdin.readline()
     if not l:
--- a/mercurial/localrepo.py	Wed Nov 05 01:52:46 2014 +0000
+++ b/mercurial/localrepo.py	Fri Oct 17 20:49:39 2014 -0700
@@ -882,7 +882,8 @@
         self._writejournal(desc)
         renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
         rp = report and report or self.ui.warn
-        tr = transaction.transaction(rp, self.sopener,
+        vfsmap = {'plain': self.opener} # root of .hg/
+        tr = transaction.transaction(rp, self.sopener, vfsmap,
                                      "journal",
                                      aftertrans(renames),
                                      self.store.createmode,
--- a/mercurial/transaction.py	Wed Nov 05 01:52:46 2014 +0000
+++ b/mercurial/transaction.py	Fri Oct 17 20:49:39 2014 -0700
@@ -70,8 +70,8 @@
             opener.unlink(f)
 
 class transaction(object):
-    def __init__(self, report, opener, journal, after=None, createmode=None,
-            onclose=None, onabort=None):
+    def __init__(self, report, opener, vfsmap, journal, after=None,
+                 createmode=None, onclose=None, onabort=None):
         """Begin a new transaction
 
         Begins a new transaction that allows rolling back writes in the event of
@@ -87,7 +87,12 @@
         self.count = 1
         self.usages = 1
         self.report = report
+        # a vfs to the store content
         self.opener = opener
+        # a map to access file in various {location -> vfs}
+        vfsmap = vfsmap.copy()
+        vfsmap[''] = opener  # set default value
+        self._vfsmap = vfsmap
         self.after = after
         self.onclose = onclose
         self.onabort = onabort