[PATCH 1 of 5] transaction: pass a vfs map to the transaction
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Sat Oct 18 11:44:53 UTC 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 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.
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 = []
More information about the Mercurial-devel
mailing list