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

Re: Enhancing --show-function and --function-context in default configurations

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 2, 2021, 08:45 UTC
Message-ID
<875ywoqldr.fsf@evledraar.gmail.com>
In-Reply-To
<CAM1Tk15N6uK3aU5bY6mWQVX5UdEOraysrRmO+v4TA+P-Wa9_hQ@mail.gmail.com>
On Sun, Aug 01 2021, heapcrash heapcrash wrote:
Show 25 quoted lines
> Hello all!
>
> Thanks to all of the Git community for making such amazing tools.
>
> Some of my favorite features of Git are the --show-function and
> --function-context features of git {grep,log,diff}.
>
> However, the default configuration leaves a bit to be desired --
> setting some simple flags in ~/.gitattributes for e.g.
>
>     *.cpp diff=cpp
>     *.py diff=python
>
> Makes these features MUCH more accurate and usable.  However, one has
> to know about gitattributes, diff filters, xfuncname, etc. in order to
> turn these settings on.
>
> I'd like to contribute changes to Git that makes the "obvious"
> correlations be the default setting.  Before I start, I wanted to
> gauge whether these changes would be accepted or not.  As far as I can
> tell, these would not change the default behavior of plain git
> {grep,log,diff} unless the --show-function or --function-context flags
> are specified -- and if they are, the results would be improved.
>
> Should I work on a patch that does this?

As Junio hinted at in his reply this doesn't just change diff behavior with the -W or --function-context flag, but changes the work we do (even if the output is the same) on all unified diff output.

I.e. to generate the "@@" context line we by default use a C function in xdiff/, this is replaced with a regex-in-a-loop invoking the userdiff.[ch] code.

I would like to see us have a setting to turn these on by default, but think it would be better to make that a diff.* config setting to put into ~/.gitconfig, i.e. we'd extend git itself to know about a list of extensions for the given userdiff drivers, and use them when rendering diffs.

It makes emitting the diffs take more CPU, but the same is true of other options like colorMoved etc, so that in itself is not a dealbreaker.

Previous: Junio C HamanoNext: Jeff King
Message 3 of 7 in “Enhancing --show-function and --function-context in default configurations”
  1. heapcrash heapcrashAug 1, 2021
  2. Junio C HamanoAug 2, 2021
  3. Ævar Arnfjörð BjarmasonAug 2, 2021
  4. Jeff KingAug 2, 2021
  5. Junio C HamanoAug 2, 2021
  6. heapcrash heapcrashAug 3, 2021
  7. Jeff KingAug 3, 2021

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.