git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/4] diffcore-delta.c: Ignore CR in CRLF for text files

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 29, 2007, 08:51 UTC
Message-ID
<7vbqezf8is.fsf@assigned-by-dhcp.pobox.com>
In-Reply-To
<200706290813.l5T8DJ6w024507@mi1.bluebottle.com>
しらいしななこ  <nanako3@bluebottle.com> writes:
Show 16 quoted lines
> Quoting Junio C Hamano <gitster@pobox.com>:
>
>> This ignores CR byte in CRLF sequence in text file when
>> computing similarity of two blobs.
>> ...
>> +test_expect_success 'diff -M' '
>> +
>> +	git diff-tree -M -r --name-status HEAD^ HEAD |
>> +	sed -e "s/R[0-9]*/RNUM/" >actual &&
>> +	echo "RNUM	sample	elpmas" >expect &&
>> +	diff -u expect actual
>> +
>> +'
>
> I tried this test but it does not give R100.  The new file is unchanged except for
> LF -> CRLF.  Could you explain why?
Heh, I hate when people nitpick me ;-)

The similarity code counts "bytes copied from the source material to the destination" and "bytes added to the source to create the destination".

Rename detection uses only the former value. The amount of data copied from the source is divided by the larger of the size of source or destination.

In the case of our test script, the source material is about 560 bytes, while the destination material is about 590 bytes, after adding CR to the end of every line. We find that 560 bytes have been copied from the source material, and floor(560 * 100 / 590) is 94%, which is what you would see as the result.

We could adjust max_size variable inside diffcore_count_changes, but I am not sure if it is worth the trouble.

Previous: しらいしななこNext: Geoff Russell
Message 8 of 9 in “Applying patches in a directory that isn't a repository”
  1. Geoff RussellJun 29, 2007
  2. Junio C HamanoJun 29, 2007
  3. 1/4 diffcore_count_changes: pass diffcore_filespecJunio C Hamano, Jun 29, 2007
  4. 2/4 diffcore_filespec: add is_binaryJunio C Hamano, Jun 29, 2007
  5. 3/4 diffcore-delta.c: update the comment on the algorithm.Junio C Hamano, Jun 29, 2007
  6. 4/4 diffcore-delta.c: Ignore CR in CRLF for text filesJunio C Hamano, Jun 29, 2007
  7. しらいしななこJun 29, 2007
  8. Junio C HamanoJun 29, 2007
  9. Geoff RussellJun 30, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.