Patchwork [2,of,7] transaction: allow to generate file with a suffix

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 18, 2014, 11:39 p.m.
Message ID <aa43d1604f651da073cf.1416353999@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6772/
State Accepted
Headers show

Comments

Pierre-Yves David - Nov. 18, 2014, 11:39 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1411979348 25200
#      Mon Sep 29 01:29:08 2014 -0700
# Node ID aa43d1604f651da073cfd87a3e2c9f7d4fb4afb4
# Parent  2589c851a997c896958803be48accd64ca30c674
transaction: allow to generate file with a suffix

This will allow use to generate pending file. File generated with a suffix are
assumed temporary and will be cleaned up at the end of the transaction.

Patch

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -260,19 +260,23 @@  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.
         self._filegenerators[genid] = (order, filenames, genfunc, location)
 
-    def _generatefiles(self):
+    def _generatefiles(self, suffix=''):
         # write files registered for generation
         for entry in sorted(self._filegenerators.values()):
             order, filenames, genfunc, location = entry
             vfs = self._vfsmap[location]
             files = []
             try:
                 for name in filenames:
-                    self.addbackup(name, location=location)
+                    name += suffix
+                    if suffix:
+                        self.registertmp(name, location=location)
+                    else:
+                        self.addbackup(name, location=location)
                     files.append(vfs(name, 'w', atomictemp=True))
                 genfunc(*files)
             finally:
                 for f in files:
                     f.close()