changeset 29273:118a605e3ad9

distate: add assertions to backup functions Those assertions will prevent the backup functions from overwriting the dirstate file in case both: suffix and prefix are empty. (foozy suggested making that change and I agree with him)
author Mateusz Kwapich <mitrandir@fb.com>
date Thu, 26 May 2016 17:36:44 -0700
parents 48b38b16a8f8
children 148a9a5379f0
files mercurial/dirstate.py
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Tue May 24 13:29:53 2016 -0700
+++ b/mercurial/dirstate.py	Thu May 26 17:36:44 2016 -0700
@@ -1211,6 +1211,7 @@
 
     def savebackup(self, tr, suffix='', prefix=''):
         '''Save current dirstate into backup file with suffix'''
+        assert len(suffix) > 0 or len(prefix) > 0
         filename = self._actualfilename(tr)
 
         # use '_writedirstate' instead of 'write' to write changes certainly,
@@ -1235,6 +1236,7 @@
 
     def restorebackup(self, tr, suffix='', prefix=''):
         '''Restore dirstate by backup file with suffix'''
+        assert len(suffix) > 0 or len(prefix) > 0
         # this "invalidate()" prevents "wlock.release()" from writing
         # changes of dirstate out after restoring from backup file
         self.invalidate()
@@ -1244,5 +1246,6 @@
 
     def clearbackup(self, tr, suffix='', prefix=''):
         '''Clear backup file with suffix'''
+        assert len(suffix) > 0 or len(prefix) > 0
         # using self._filename to avoid having "pending" in the backup filename
         self._opener.unlink(prefix + self._filename + suffix)