# HG changeset patch # User Jun Wu # Date 2017-03-02 01:59:21 # Node ID 1ef37b16b8e839dec3a9bd018992b405def366e7 # Parent 49e5491ed9bd29e55330e2079c6d087e7c6d973c 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 @@ -1235,8 +1235,14 @@ class dirstate(object): # end of this transaction 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=''): '''Restore dirstate by backup file with suffix''' 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 @@ -5,7 +5,11 @@ Test how largefiles abort in case the di > from mercurial import util > # > # 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)) > shutil.copyfileobj = copyfileobj