[PATCH 2 of 2 v3] add: notify when adding a file that would cause a case-folding collision

Adrian Buehlmann adrian at cadifra.com
Sat Apr 30 12:15:21 CDT 2011


On 2011-04-30 14:37, Kevin Gessner wrote:
> # HG changeset patch
> # User Kevin Gessner <kevin at kevingessner.com>
> # Date 1304159986 -7200
> # Node ID ff0e87163b43ce808f9dbde1689e6bc18a0735e9
> # Parent  7d8f45c157752f91ae4daa590146463c1bbb304c
> add: notify when adding a file that would cause a case-folding collision
> 
> On a case-sensitive file system, files can be added with names that differ
> only in case (a "case collision"). This would cause an error on case-insensitive
> filesystems. A warning or error is now given for such collisions, depending on
> the value of ui.portablefilenames ('warn', 'abort', or 'ignore'):
> 
>     $ touch file File
>     $ hg add --config ui.portablefilenames=abort File
>     abort: possible case-folding collision for File
>     $ hg add File
>     warning: possible case-folding collision for File
> 
> diff -r 7d8f45c15775 -r ff0e87163b43 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py	Sat Apr 30 11:08:24 2011 +0200
> +++ b/mercurial/cmdutil.py	Sat Apr 30 12:39:46 2011 +0200
> @@ -1314,9 +1314,16 @@
>      match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
>      names = []
>      wctx = repo[None]
> +    wctx.status(clean=True)
> +    existing = None
> +    if scmutil.showportabilityalert(ui):
> +        existing = dict([(fn.lower(), fn) for fn in
> +                         wctx.added() + wctx.clean() + wctx.modified()])
>      for f in repo.walk(match):
>          exact = match.exact(f)
>          if exact or f not in repo.dirstate:
> +            if existing:
> +                scmutil.checkcasecollision(ui, f, existing)

Here, you indirectly call scmutil.checkportabilityalert [which in turn
calls ui.config] on each and every loop iteration.

The showportabilityalert call right above adds yet another call.

Doesn't look particularly efficient/elegant. It should be possible to
consult the config a single time per this whole scope.

>              names.append(f)
>              if ui.verbose or not exact:
>                  ui.status(_('adding %s\n') % match.rel(join(f)))


More information about the Mercurial-devel mailing list