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

Kevin Gessner kevin at fogcreek.com
Sat Apr 30 13:15:00 CDT 2011


On Apr 30, 2011, at 7:15 PM, Adrian Buehlmann wrote:

> 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
>> ........
>> 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.

I must not be understanding you. scmutil.checkcasecollision only does a config read (via portabilityalert) on each collision, not on every iteration. That's certainly not optimal, but means that for an add without collisions there is exactly one config read (in scmutil.showportabilityalert). Right?

I agree that this could be written with strictly fewer config reads, but I don't think there's an algorithmic win here.



More information about the Mercurial-devel mailing list