Patchwork [4,of,6] dirstate: make writing dirstate file out avoid ambiguity of file stat

mail settings
Submitter Katsunori FUJIWARA
Date June 2, 2016, 3:47 p.m.
Message ID <9d61f363d6a40d860e60.1464882464@feefifofum>
Download mbox | patch
Permalink /patch/15363/
State Accepted
Headers show


Katsunori FUJIWARA - June 2, 2016, 3:47 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# Date 1464882260 -32400
#      Fri Jun 03 00:44:20 2016 +0900
# Node ID 9d61f363d6a40d860e609fc56313cd21c5830413
# Parent  da47f1b8acc26dfba7592ee051fbdb6fb519ae2a
dirstate: make writing dirstate file out avoid ambiguity of file stat

Cached attribute repo.dirstate uses stat of '.hg/dirstate' file to
examine validity of cached contents. If writing '.hg/dirstate' file
out keeps ctime, mtime and size of it, change is overlooked, and old
contents cached before change isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/dirstate' file
out with checkambig=True.

The former diff hunk changes the code path for "dirstate.write()", and
the latter changes the code path for "dirstate.savebackup()".

This patch is a part of "Exact Cache Validation Plan":


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -730,7 +730,7 @@  class dirstate(object):
                                 self._writedirstate, location='plain')
-        st = self._opener(filename, "w", atomictemp=True)
+        st = self._opener(filename, "w", atomictemp=True, checkambig=True)
     def _writedirstate(self, st):
@@ -1217,7 +1217,8 @@  class dirstate(object):
         # use '_writedirstate' instead of 'write' to write changes certainly,
         # because the latter omits writing out if transaction is running.
         # output file will be used to create backup of dirstate at this point.
-        self._writedirstate(self._opener(filename, "w", atomictemp=True))
+        self._writedirstate(self._opener(filename, "w", atomictemp=True,
+                                         checkambig=True))
         if tr:
             # ensure that subsequent tr.writepending returns True for