[PATCH] fix regression reported in 1286

Matt Mackall mpm at selenic.com
Fri Sep 5 19:53:49 CDT 2008


On Fri, 2008-09-05 at 11:16 -0400, Petr Kodl wrote:
> # HG changeset patch
> # User Petr Kodl <petrkodl at gmail.com>
> # Date 1220627655 14400
> # Node ID 0d365d58e33635c5851abc206ad045036d9ad998
> # Parent  4e62be0208d3465cf241d8fb6fb7c9ce125a490b
> fix regression reported in 1286
> 
> diff -r 4e62be0208d3 -r 0d365d58e336 mercurial/dirstate.py
> --- a/mercurial/dirstate.py	Fri Sep 05 11:04:36 2008 +0200
> +++ b/mercurial/dirstate.py	Fri Sep 05 11:14:15 2008 -0400
> @@ -94,7 +94,9 @@
>              if self._checkcase:
>                  self.normalize = self._normalize
>              else:
> -                self.normalize = lambda x: x
> +                def dummy_normalize(path, use_normpath=False): 
> +                    return path
> +                self.normalize = dummy_normalize
>              return self.normalize
>          else:
>              raise AttributeError, name
> @@ -345,14 +347,20 @@
>              del self._map[f]
>          except KeyError:
>              self._ui.warn(_("not in dirstate: %s\n") % f)
> -
> -    def _normalize(self, path):
> -        norm_path = os.path.normcase(os.path.normpath(path))
> -        if norm_path not in self._foldmap:
> -            if not os.path.exists(os.path.join(self._root, path)):
> -                return path
> -            self._foldmap[norm_path] = util.fspath(path, self._root)
> -        return self._foldmap[norm_path]
> +    
> +    def _normalize(self, path, use_normpath=False):
> +        norm_path = os.path.normcase(path)
> +        fold_path = self._foldmap.get(norm_path,None)
> +        if fold_path is None:
> +            if use_normpath:
> +                fold_path = norm_path
> +            else:
> +                if not os.path.exists(os.path.join(self._root, path)):
> +                    fold_path = path
> +                else:
> +                    fold_path = util.fspath(path, self._root)
> +                    self._foldmap[norm_path] = fold_path
> +        return fold_path

This undoes a few micro-optimizations in the fast path and drops the
call to normpath. It also turns out to be faster to do:

if x in m:
   a = m[x]

than

a = m.get(x)

..especially if you have to do a subsequent test.

So this might want to look like:

fm = self._foldmap
normpath = ... 
if normpath not in fm:
  if usenormpath: # underbars: don't use 'em
    return normpath
  t = fm[normpath] = util.fspath(path, self._root)
  return t
return fm[normpath]

util.fspath ought to internalize the existence check.

Also, returning the normcase'd version here looks just wrong.

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list