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

Re: [PATCH 1/2] diffcore-break: don't divide by zero

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 2, 2013, 22:41 UTC
Message-ID
<7va9pga73t.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130402213651.GG2222@serenity.lan>
John Keeping <john@keeping.me.uk> writes:
> The message for commit 6dd4b66 (Fix diffcore-break total breakage)
> indicates that "don't bother to break small files" is wrong in some
> cases, but it I wonder if "don't bother to break empty files" is okay.

This has a rather subtle ramifications, and we would need to think carefully. "break" does two very different things, and the criteria you would want to use to decide to "break" a filepair depends on which one you are interested in.

The very original motivation of "break" was to show a patch that rewrites an existing file completely in a way different from the usual "diff -u" output, which will try to minimize the output by finding (rare) lines that happen to be the same between the preimage and postimage, intersparsed in many lines of "-" (deletion) and "+" (addition). Such a change is often easier to understand when shown as a single block of "-" (deletion) of the entire original contents, followed by a single block of "+" (addition) of the entire new contents.

A totally separate motivation of "break" is the one Linus talks about in the log message of the said commit. A path filename.h was moved to filename_32.h, and a new (and much smaller) filename.h was introduced, that "#include"s filename_32.h. "diff -M" that pairs deleted files with created files to compute renames in such a case would not consider the original filename.h as a possible source of filename_32.h that was created. You want to break modification of filename.h into (virtual) deletion and addition of filename.h.

For the purpose of the former, you would want not to break a file too aggressively. If you started from a file with 1000 lines in it, and deleted 910 lines and added 10 lines to result in a file with 100 lines, you still have 90 lines of shared contents between the preimage and the postimage, and you do not want to show it as "delete 1000 lines and add 100 lines". You would want to base your decision on how much common material exists between the two.

For the purpose of the latter, however, it is better to err on the side of breaking than not breaking. After breaking a suspicious modification into addition and deletion, if rename comparison does not find a suitable destination for the virtual deletion, the broken halves will be merged back, so breaking too little can hurt by missing potential renames, but breaking too much will not. You do want to break the "900 deleted out of 1000 and then added 10" case, as that 900 lines may have gone to another file that was created in the same commit. "But we have 90 lines of common material" does not matter for the decision to break.

In today's code, the return value of should_break() is about the latter, while the score it stores in *merge_score is about the former.

Previous: John KeepingNext: John Keeping
Message 5 of 9 in “Fixes for undefined behaviour”
  1. 0/2 Fixes for undefined behaviourJohn Keeping, Apr 2, 2013
  2. 1/2 diffcore-break: don't divide by zeroJohn Keeping, Apr 2, 2013
  3. Junio C HamanoApr 2, 2013
  4. John KeepingApr 2, 2013
  5. Junio C HamanoApr 2, 2013
  6. diffcore-break: don't divide by zeroJohn Keeping, Apr 3, 2013
  7. 2/2 bisect: avoid signed integer overflowJohn Keeping, Apr 2, 2013
  8. Junio C HamanoApr 2, 2013
  9. John KeepingApr 3, 2013

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.