[PATCH 3 of 6 STABLE V3] dirstate: use util.normcase() instead of str.lower() or os.path.normcase()

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Dec 13 07:08:05 CST 2011


At Mon, 12 Dec 2011 22:25:39 +0900,
FUJIWARA Katsunori wrote:
> 
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1323677419 -32400
> # Branch stable
> # Node ID d7229f60ad8aacd657d780935235a84048413dc6
> # Parent  7ef5cd9f4a5501388f73efb1f225c52e87acef76
> dirstate: use util.normcase() instead of str.lower() or os.path.normcase()
> 
> to omit normcase()-ing to specified path in util.fspath(), this patch
> passes already normcase()-ed path to it.
> 
> in other hand, directory contents should be normcase()-ed to compare
> with it, because they are already almost normalized, but not yet in
> case.
> 
> this patch includes some other changes to accept both lower/upper as
> normcase logic. these are tradeoff for omiting complex string
> operations to preserve case in fspath().
> 
> 1. put '.' into foldmap of dirstate to prevent useless util.fspath()
>    invocation:
> 
>    at first of dirstate.walk(), normalization of '.' causes
>    util.fspath() invocation, but '.' is not cached in it.
> 
>    this invocation is not only useless, but also harmful: initial "hg
>    tag" causes creation of ".hgtags" file after dirstate.walk(), and
>    looking up ".hgtags" in cache will fail, because directory contents
>    of root is already cached at util.fspath() invocation for '.'.
> 
> 2. retry directory scan once for already invalidated cache:
> 
>    some hg operation (e.g.: qpush) create new files after first
>    dirstate.walk()-ing, and it invalidates _fspathcache for fspath().
> 
>    then, fspath() is invoked with already normcase()-ed path, so this
>    invalidation causes breaking case preservation.
> 
>    in this case, file system I/O should be done before fspath()
>    invocation, so the second invocation of os.listdir() has not so
>    much impact on runtime performance.
> 
> 3. separate path absoluteness check from fspath():
> 
>    if path absoluteness check is really required, it should be applied
>    in dirstate._normalize(), because fspath() is used only from it
>    now.
> 
>    and in fact, cygwin environment fails "os.path.lexists()" with
>    fully upper cased root, so both plain and normcase()-ed roots are
>    required for fspath(), if path absoluteness check is done in it.

I wrote this patch also to reduce some duplicated operations in
util.fspath() for dirstate._normalize():

  - os.path.lexists() to specified path:
    * dirstate already checks it

  - lower and normcase on specified root
    * dirstate can cache normcase()-ed one and reuse it

  - lower (as normcase) on specified path
    * dirstate already has normcase()-ed path

but I'll post another patches, if fspath() API specificatoin should be
kept !

# or separate optimization from 'util.normcase()'-nize ?

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp


More information about the Mercurial-devel mailing list