[PATCH 5 of 7 🚂] transaction: drop backupentries logic from startgroup and endgroup

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Nov 10 10:31:50 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1415181938 0
#      Wed Nov 05 10:05:38 2014 +0000
# Node ID d648190dde0ef6d2378700bfc780147ff782fe1e
# Parent  98d4dd03994f46807a06ec13ef5d1d1678366cb7
transaction: drop backupentries logic from startgroup and endgroup

The `startgroup` and `endgroup` methodes are used in the very specific context
to wrap very specific operation (revlog truncation). It does not make sense to
perform any other operation during such "group" (eg:file backup). There is
currently no user of backupfile during a "group" so we drop the group-specific
code and restrict authorized operation during "group".

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -119,44 +119,35 @@ class transaction(object):
     def startgroup(self):
         """delay registration of file entry
 
         This is used by strip to delay vision of strip offset. The transaction
         see either none or all strip action to be done."""
-        self._queue.append(([], []))
+        self._queue.append([])
 
     @active
     def endgroup(self):
         """apply delayed registration of file entry.
 
         This is used by strip to delay vision of strip offset. The transaction
         see either none or all strip action to be done."""
         q = self._queue.pop()
-        self.entries.extend(q[0])
-        self._backupentries.extend(q[1])
+        self.entries.extend(q)
 
         offsets = []
-        backups = []
-        for f, o, _data in q[0]:
+        for f, o, _data in q:
             offsets.append((f, o))
 
-        for f, b in q[1]:
-            backups.append((f, b))
-
         d = ''.join(['%s\0%d\n' % (f, o) for f, o in offsets])
         self.file.write(d)
         self.file.flush()
 
-        d = ''.join(['%s\0%s\n' % (f, b) for f, b in backups])
-        self._backupsfile.write(d)
-        self._backupsfile.flush()
-
     @active
     def add(self, file, offset, data=None):
         if file in self.map or file in self._backupmap:
             return
         if self._queue:
-            self._queue[-1][0].append((file, offset, data))
+            self._queue[-1].append((file, offset, data))
             return
 
         self.entries.append((file, offset, data))
         self.map[file] = len(self.entries) - 1
         # add enough data to the journal to do the truncate
@@ -172,10 +163,13 @@ class transaction(object):
         aborting.
 
         * `file`: the file path, relative to .hg/store
         * `hardlink`: use a hardlink to quickly create the backup
         """
+        if self._queue:
+            msg = 'cannot use transaction.addbackup inside "group"'
+            raise RuntimeError(msg)
 
         if file in self.map or file in self._backupmap:
             return
         backupfile = "%s.backup.%s" % (self.journal, file)
         if vfs is None:
@@ -186,14 +180,10 @@ class transaction(object):
             util.copyfiles(filepath, backuppath, hardlink=hardlink)
         else:
             self.add(file, 0)
             return
 
-        if self._queue:
-            self._queue[-1][1].append((file, backupfile))
-            return
-
         self._backupentries.append((file, backupfile))
         self._backupmap[file] = len(self._backupentries) - 1
         self._backupsfile.write("%s\0%s\n" % (file, backupfile))
         self._backupsfile.flush()
 


More information about the Mercurial-devel mailing list