Re: [PATCH] diff: round down similarity index
- From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
- Date
- Jun 25, 2007, 01:29 UTC
- Message-ID
- <467F1A77.3030209@lsrfire.ath.cx>
- In-Reply-To
- <Pine.LNX.4.64.0706250026400.4059@racer.site>
Johannes Schindelin schrieb:
Show 24 quoted lines
> Hi,
>
> On Mon, 25 Jun 2007, Johannes Schindelin wrote:
>
>> On Mon, 25 Jun 2007, Ren� Scharfe wrote:
>>
>>> Rounding down the printed (dis)similarity index allows us to use
>>> "100%" as a special value that indicates complete rewrites and
>>> fully equal file contents, respectively.
>>>
>>> [...]
>>>
>>> +static int similarity_index(struct diff_filepair *p)
>>> +{
>>> + int result = p->score * 100.0 / MAX_SCORE;
>>> +
>>> + /* Paranoia: guard against floating point rounding errors. */
>>> + if (p->score == MAX_SCORE)
>>> + result = 100;
>>> + else if (result == 100)
>>> + result = 99;
>>> +
>>> + return result;
>>> +}>> Besides, AFAIR p->score is not even calculated if the files are identical, >> because that hits a different code path.
True, ->score is set to MAX_SCORE for identical files by a different code path than the one that actually compares the contents and calculates a score. That doesn't matter for printing the "similarity index nn%" line etc., though. Or is there a way for identical files to end up with a ->score of 0 (or some other value != MAX_SCORE) that I missed?
In any case, the patch doesn't change the way the score is calculated, i.e. its value is the same as before. It only changes how it is displayed.
René