[PATCH 1 of 5 V2] dirstate: try to use hardlink to backup dirstate

Jun Wu quark at fb.com
Fri Mar 3 06:13:27 UTC 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1488419961 28800
#      Wed Mar 01 17:59:21 2017 -0800
# Node ID 44cbc7533adfb66e687e4b28312b166f32b01ce0
# Parent  b4cd912d7704cd976e1bee3a3c927e0e578ec88f
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 44cbc7533adf
dirstate: try to use hardlink to backup dirstate

This should be more efficient once util.copyfile has real hardlink support.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1225,6 +1225,12 @@ class dirstate(object):
             tr.registertmp(filename, location='plain')
 
-        self._opener.write(prefix + self._filename + suffix,
-                           self._opener.tryread(filename))
+        backupname = prefix + self._filename + suffix
+        assert backupname != filename
+        if self._opener.exists(backupname):
+            self._opener.unlink(backupname)
+        # hardlink backup is okay because _writedirstate is always called
+        # with an "atomictemp=True" file.
+        util.copyfile(self._opener.join(filename),
+                      self._opener.join(backupname), hardlink=True)
 
     def restorebackup(self, tr, suffix='', prefix=''):
diff --git a/tests/test-largefiles-small-disk.t b/tests/test-largefiles-small-disk.t
--- a/tests/test-largefiles-small-disk.t
+++ b/tests/test-largefiles-small-disk.t
@@ -6,5 +6,9 @@ Test how largefiles abort in case the di
   > #
   > # this makes the original largefiles code abort:
+  > _origcopyfileobj = shutil.copyfileobj
   > def copyfileobj(fsrc, fdst, length=16*1024):
+  >     # allow journal files (used by transaction) to be written
+  >     if 'journal.' in fdst.name:
+  >         return _origcopyfileobj(fsrc, fdst, length)
   >     fdst.write(fsrc.read(4))
   >     raise IOError(errno.ENOSPC, os.strerror(errno.ENOSPC))


More information about the Mercurial-devel mailing list