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

Re: diffutils: C labels misdetected as functions

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 22, 2007, 21:30 UTC
Message-ID
<7vtzrwqg87.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<46A3AD07.1070504@simon.arlott.org.uk>
Simon Arlott <simon@fire.lp0.eu> writes:
Show 12 quoted lines
> On 22/07/07 19:38, Paul Eggert wrote:
>> 
>> Anyway, to work around your problem without changing "diff", you can
>> use "diff -u -F '^[[:alpha:]$_](|.*[^:])$'" instead of "diff -u -p".
>
> Perhaps git could do this (or similar) as a workaround? (Cc:ed)
>
>> Or you can put a single space before the labels in question: they'll
>> still stand out plenty.
>
> The code should definitely not need to be modified to work around a
> diff bug.

I think the word "bug" is just about documentation. Promising "show C function" and including labels and/or not showing all functions would be a bug, but given that diff is about showing textual differences between two text files with arbitrary kind of contents, I do not think it is reasonable to take that "show C function" promise too literally.

To avoid this, the description of the feature could be reworded to "shows lines that match pattern '^[[:alpha:]$_]' on context lines, intent of the option being that the pattern tends to match the beginning of function in C language and help the reader to locate the context more easily, with a caveat that the pattern matching is not meant to capture all functions nor only functions --- there will be false matches."

But that would be too long. And as Paul showed, you can narrow or widen the set of lines that are shown with the -F option. I do not think this deserves to be called a "bug".

You can define your own customized "function name" pattern in your .git/config (or $HOME/.gitconfig) file to be used by the git-diff family with recent enough git via the attributes mechanism, but I do not think we should change the default, unless GNU diff changes its default. Personally I'd rather not see it change, though.

Previous: Simon Arlott
Message 2 of 2 in “Re: diffutils: C labels misdetected as functions”
  1. Simon ArlottJul 22, 2007
  2. Junio C HamanoJul 22, 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.