[PATCH 1 of 2 sqldirstate] sqldirstate: specify checkambig=True to avoid file stat ambiguity

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Oct 14 19:10:52 UTC 2016


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1476456912 -32400
#      Fri Oct 14 23:55:12 2016 +0900
# Node ID 72486917916f6d47525f721cd5b27012091122ed
# Parent  d2c3a2c02eb6c7e5a7331ba0cf15e5bf7c8dc8dc
# Available At https://foozy@bitbucket.org/foozy/hg-experimental
#              hg pull https://foozy@bitbucket.org/foozy/hg-experimental -r 72486917916f
sqldirstate: specify checkambig=True to avoid file stat ambiguity

With sqldirstate extension, size of .hg/dirstate is always fixed: node
ID x 2 + dummy fixed text.

This increases occurrence of file stat ambiguity, and
processes/threads running parallelly might overlook change of
dirstate, because reloading @filecache-ed property repo.dirstate is
avoided in such case. See wiki page below for detail about file stat
ambiguity.

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan

This patch specifies checkambig=True at opening .hg/dirstate file for
writing, to avoid file stat ambiguity.

Strictly speaking, to enable sqldirstate with Mercurial earlier than
upcoming 4.0 (or 76f1ea360c7e), it should be examined whether
checkambig optional argument is available for opener or not, because
it has been available since 4.0 (or 76f1ea360c7e).

But current sqldirstate implementation depends on 2ebd507e5ac3 of
Mercurial, which has introduced dirstate._origpl after 76f1ea360c7e.

Therefor, changes in this patch are safe enough, unless removing
dependence on dirstate._origpl from sqldirstate.

diff --git a/sqldirstate/sqldirstate.py b/sqldirstate/sqldirstate.py
--- a/sqldirstate/sqldirstate.py
+++ b/sqldirstate/sqldirstate.py
@@ -563,7 +563,7 @@ def makedirstate(cls):
 
 
 def writefakedirstate(dirstate):
-    st = dirstate._opener(FAKEDIRSTATE, "w", atomictemp=True)
+    st = dirstate._opener(FAKEDIRSTATE, "w", atomictemp=True, checkambig=True)
     st.write("".join(dirstate._pl))
     st.write("\nThis is fake dirstate put here by the sqldirsate.")
     st.write("\nIt contains only working copy parents info.")
@@ -629,7 +629,7 @@ def toflat(sqldirstate):
     it's not touching anything but the dirstate file
     """
     # converts a sqldirstate to a flat one
-    st = sqldirstate._opener("dirstate", "w", atomictemp=True)
+    st = sqldirstate._opener("dirstate", "w", atomictemp=True, checkambig=True)
     newmap = {}
     for k, v in sqldirstate._map.iteritems():
         newmap[k] = v


More information about the Mercurial-devel mailing list