# HG changeset patch # User Pierre-Yves David # Date 1413604179 25200 # Node ID 5bd1f6572db0efe7bad6f0c75d69364209fe2604 # Parent 7eb520f5efe4d07ba21b1a82b61a4d542722d3d4 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 -r 7eb520f5efe4 -r 5bd1f6572db0 contrib/undumprevlog --- 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: diff -r 7eb520f5efe4 -r 5bd1f6572db0 mercurial/localrepo.py --- 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, diff -r 7eb520f5efe4 -r 5bd1f6572db0 mercurial/transaction.py --- 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