[PATCH 1 of 3 V2] dirstate: add prefix and suffix arguments to backup

Mateusz Kwapich mitrandir at fb.com
Wed May 11 21:30:42 UTC 2016


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1462992531 25200
#      Wed May 11 11:48:51 2016 -0700
# Node ID a1b956549c45a0191956bc074f276bd18afd40c1
# Parent  c641b8dfb98c2ade6995ba3aa341fe4d7b154827
dirstate: add prefix and suffix arguments to backup

This would allow the code explicutly copying dirstate to use this method instead.
Use of this method will increase encapsulation (the dirstate class will be sole
owner of its on-disk storage).

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1205,7 +1205,7 @@ class dirstate(object):
         else:
             return self._filename
 
-    def savebackup(self, tr, suffix):
+    def savebackup(self, tr, suffix='', prefix=''):
         '''Save current dirstate into backup file with suffix'''
         filename = self._actualfilename(tr)
 
@@ -1226,17 +1226,18 @@ class dirstate(object):
             # end of this transaction
             tr.registertmp(filename, location='plain')
 
-        self._opener.write(filename + suffix, self._opener.tryread(filename))
+        self._opener.write(prefix + filename + suffix,
+                           self._opener.tryread(filename))
 
-    def restorebackup(self, tr, suffix):
+    def restorebackup(self, tr, suffix='', prefix=''):
         '''Restore dirstate by backup file with suffix'''
         # this "invalidate()" prevents "wlock.release()" from writing
         # changes of dirstate out after restoring from backup file
         self.invalidate()
         filename = self._actualfilename(tr)
-        self._opener.rename(filename + suffix, filename)
+        self._opener.rename(prefix + filename + suffix, filename)
 
-    def clearbackup(self, tr, suffix):
+    def clearbackup(self, tr, suffix='', prefix=''):
         '''Clear backup file with suffix'''
         filename = self._actualfilename(tr)
-        self._opener.unlink(filename + suffix)
+        self._opener.unlink(prefix + filename + suffix)


More information about the Mercurial-devel mailing list