Patchwork [1,of,5] transaction: pass a vfs map to the transaction

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 18, 2014, 11:44 a.m.
Message ID <c5f48e3801a9393a0a31.1413632693@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6400/
State Superseded
Commit 5bd1f6572db0efe7bad6f0c75d69364209fe2604
Headers show

Comments

Pierre-Yves David - Oct. 18, 2014, 11:44 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1413604179 25200
#      Fri Oct 17 20:49:39 2014 -0700
# Node ID c5f48e3801a9393a0a318b1b01effba1dc110ea1
# Parent  f484be02bd351fbd084d93f5ba4180e2b22cd4eb
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.
Pierre-Yves David - Oct. 18, 2014, 11:50 a.m.
On 10/18/2014 04:44 AM, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1413604179 25200
> #      Fri Oct 17 20:49:39 2014 -0700
> # Node ID c5f48e3801a9393a0a318b1b01effba1dc110ea1
> # Parent  f484be02bd351fbd084d93f5ba4180e2b22cd4eb
> transaction: pass a vfs map to the transaction

Those 5 patches are the most complexe one. After this I've 11 smaller 
and simpler changesets that use this improvement to rationalize the 
handling of pending and generated file during transaction.
Matt Mackall - Oct. 18, 2014, 8:16 p.m.
On Sat, 2014-10-18 at 04:44 -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1413604179 25200
> #      Fri Oct 17 20:49:39 2014 -0700
> # Node ID c5f48e3801a9393a0a318b1b01effba1dc110ea1
> # Parent  f484be02bd351fbd084d93f5ba4180e2b22cd4eb
> transaction: pass a vfs map to the transaction

Didn't you ask me just yesterday if you should send this and I said
"wait until the freeze"? Deleted with extreme prejudice.

Patch

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
@@ -877,11 +877,13 @@  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 = {'store': self.sopener, # store
+                  '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
@@ -57,12 +57,12 @@  def _playback(journal, report, opener, e
         opener.unlink(backuppath)
     for f in backupfiles:
         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.
 
@@ -74,11 +74,14 @@  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}
+        self._vfsmap = vfsmap
         self.after = after
         self.onclose = onclose
         self.onabort = onabort
         self.entries = []
         self.backupentries = []