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

gitk: add "grep diff" selection criterion (Re: find commit adding/removing could use changing option)

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 16, 2010, 17:28 UTC
Message-ID
<20100716172806.GA15491@burratino>
In-Reply-To
<D163BB49BCC4479AB3E4BA4F87826184@csmith>
Hi Chris,
Chris Smith wrote:
Show 8 quoted lines
> One thing I find myself wishing for is the ability to find a line that has
> been modified by using gitk. It seems to me that if I have the following in a
> diff
> 
> - def foo(this)
> + def foo(this, that=False)
> 
> that I can't find the line by searching for foo.

Ah, so you want a cousin to ‘log -S’ that /does/ search through diffs. See [1].

As that thread explains, it is doable from the commandline already, though not in a nicely packaged form. But what about from gitk?

A possible hack would be to teach gitk to add arbitrary criteria to the end of the ‘git diff-tree’ command line[2]. In this case, the criterion would be ‘| search-diff $term’, where search-diff is a script something like the following:

 #!/bin/sh
 while read -r commit
 do
	if
		git diff-tree -p -c "$commit" | grep -q "$@"
	then
		printf '%s\n' "$commit"
	fi
 done

If that proves useful, afterwards one could teach ‘diff-tree’ to do the check itself, which would allow commands like

 git log --search-diff=foo
too.

Thoughts? Jonathan

[1] http://thread.gmane.org/gmane.comp.version-control.git/122478 [2] You can find the code one would need to touch for this by searching for gdtargs and gdttype in the gitk script.

Next: Junio C Hamano
Message 1 of 2 in “gitk: add "grep diff" selection criterion (Re: find commit adding/removing could use changing option)”
  1. Jonathan NiederJul 16, 2010
  2. Junio C HamanoJul 19, 2010

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.