transaction: extract file generation into its own function stable
authorPierre-Yves David <pierre-yves.david@fb.com>
Mon, 29 Sep 2014 00:59:25 -0700
branchstable
changeset 23102 16da812ad970
parent 23101 b564330d4b1f
child 23103 29bfa964d6d8
transaction: extract file generation into its own function We extract the code generating files into 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.
mercurial/transaction.py
--- a/mercurial/transaction.py	Tue Oct 28 23:05:19 2014 -0400
+++ b/mercurial/transaction.py	Mon Sep 29 00:59:25 2014 -0700
@@ -205,6 +205,26 @@
         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:
@@ -246,25 +266,7 @@
     @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()