[PATCH 2 of 5] transaction: pass a vfs map to the transaction

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Nov 13 17:39:18 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1413604179 25200
#      Fri Oct 17 20:49:39 2014 -0700
# Node ID f156e9a258e17284b5c6d8608346ca9e91077ee8
# Parent  dba745ba04b9bc614d422e2e88b362a3bbda6948
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 ''.

diff --git a/contrib/undumprevlog b/contrib/undumprevlog
--- a/contrib/undumprevlog
+++ b/contrib/undumprevlog
@@ -8,11 +8,12 @@ from mercurial import revlog, node, scmu
 
 for fp in (sys.stdin, sys.stdout, sys.stderr):
     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:
         break
     if l.startswith("file:"):
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -880,11 +880,12 @@ class localrepository(object):
             self.store.write(self._transref())
 
         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,
                                      onclose)
         self._transref = weakref.ref(tr)
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -68,12 +68,12 @@ def _playback(journal, report, opener, e
     for f in backupfiles:
         if opener.exists(f):
             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
         an exception.
 
@@ -85,11 +85,16 @@ class transaction(object):
         have been truncated
         """
         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
         self.entries = []
         self.map = {}


More information about the Mercurial-devel mailing list