[PATCH 1 of 3 V2] dirstate: don't use actualfilename to name the backup file

Mateusz Kwapich mitrandir at fb.com
Fri May 27 00:58:41 UTC 2016


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1464219376 25200
#      Wed May 25 16:36:16 2016 -0700
# Node ID 56a7e414f1f34cc8e5364457a0ec948f4074e75a
# Parent  ceca932c080d0de52ece0e8dd0226f006c7b9cb1
dirstate: don't use actualfilename to name the backup file

The issue with using actualfilename is that dirstate saved during transaction
with "pending" in filename will be impossible to recover from outside of the
transaction because the recover method will be looking for the name without
"pending".

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1228,7 +1228,7 @@ class dirstate(object):
             # end of this transaction
             tr.registertmp(filename, location='plain')
 
-        self._opener.write(prefix + filename + suffix,
+        self._opener.write(prefix + self._filename + suffix,
                            self._opener.tryread(filename))
 
     def restorebackup(self, tr, suffix='', prefix=''):
@@ -1237,9 +1237,10 @@ class dirstate(object):
         # changes of dirstate out after restoring from backup file
         self.invalidate()
         filename = self._actualfilename(tr)
-        self._opener.rename(prefix + filename + suffix, filename)
+        # using self._filename to avoid having "pending" in the backup filename
+        self._opener.rename(prefix + self._filename + suffix, filename)
 
     def clearbackup(self, tr, suffix='', prefix=''):
         '''Clear backup file with suffix'''
-        filename = self._actualfilename(tr)
-        self._opener.unlink(prefix + filename + suffix)
+        # using self._filename to avoid having "pending" in the backup filename
+        self._opener.unlink(prefix + self._filename + suffix)


More information about the Mercurial-devel mailing list