[PATCH 01 of 10] transaction: extract file generation in its own function
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Tue Oct 28 15:41:15 UTC 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1411977565 25200
# Mon Sep 29 00:59:25 2014 -0700
# Branch stable
# Node ID 5ccb5eb0a6dedf6910ed95434b6dde95b5e473c5
# Parent 6df4bc39f6828e8aa74b33e51bc72eac621db2fe
transaction: extract file generation in its own function
We extract the code generating file to its own function. We are about to move
this code around to fix a bug. We'll need it in a function soon to reuse it for
"pending" logic. So we move the code into a function instead of moving it twice.
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -203,10 +203,30 @@ class transaction(object):
# For now, we are unable to do proper backup and restore of custom vfs
# but for bookmarks that are handled outside this mechanism.
assert vfs is None or filenames == ('bookmarks',)
self._filegenerators[genid] = (order, filenames, genfunc, vfs)
+ def _generatefiles(self):
+ # write files registered for generation
+ for entry in sorted(self._filegenerators.values()):
+ order, filenames, genfunc, vfs = entry
+ if vfs is None:
+ vfs = self.opener
+ files = []
+ try:
+ for name in filenames:
+ # Some files are already backed up when creating the
+ # localrepo. Until this is properly fixed we disable the
+ # backup for them.
+ if name not in ('phaseroots', 'bookmarks'):
+ self.addbackup(name)
+ files.append(vfs(name, 'w', atomictemp=True))
+ genfunc(*files)
+ finally:
+ for f in files:
+ f.close()
+
@active
def find(self, file):
if file in self.map:
return self.entries[self.map[file]]
if file in self.backupmap:
@@ -244,29 +264,11 @@ class transaction(object):
return self.count > 0
@active
def close(self):
'''commit the transaction'''
- # write files registered for generation
- for entry in sorted(self._filegenerators.values()):
- order, filenames, genfunc, vfs = entry
- if vfs is None:
- vfs = self.opener
- files = []
- try:
- for name in filenames:
- # Some files are already backed up when creating the
- # localrepo. Until this is properly fixed we disable the
- # backup for them.
- if name not in ('phaseroots', 'bookmarks'):
- self.addbackup(name)
- files.append(vfs(name, 'w', atomictemp=True))
- genfunc(*files)
- finally:
- for f in files:
- f.close()
-
+ self._generatefiles()
if self.count == 1 and self.onclose is not None:
self.onclose()
self.count -= 1
if self.count != 0:
More information about the Mercurial-devel
mailing list