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

Re: git grep --threads 12 --textconv is effectively single-threaded

From
Jeff King <peff@peff.net>
Date
Jul 8, 2020, 20:13 UTC
Message-ID
<20200708201353.GA2354599@coredump.intra.peff.net>
In-Reply-To
<CAMP9c5mpJ9_HvEBTiEQj=vocTdH6N9uXkpLKiE8+hFbAt9p5Ow@mail.gmail.com>
On Wed, Jul 08, 2020 at 12:40:49PM -0500, Zach Riggle wrote:
Show 5 quoted lines
> So I just need to
> 
> git -c "diff.c.cachetextconv=true" ...
> 
> And the cache should automagically work?
Yes, but there's a bit of subtlety with what you're grepping.
Try this example setup:
  git init -q repo
  cd repo
  echo content >file
  echo 'file diff=foo' >.gitattributes
  git add .
  git commit -m base
  git config diff.foo.textconv 'echo >&2 converting...; sleep 1; tr a-z A-Z <'
which should make it clear when the filter actually runs.
Now try this:
  echo >&2 "==> no textconv"
  git grep . file
  echo >&2 "==> with textconv"
  git grep --textconv . file
  echo >&2 "==> cached (one)"
  git -c diff.foo.cachetextconv=true grep --textconv . file
  echo >&2 "==> cached (two)"
  git -c diff.foo.cachetextconv=true grep --textconv . file

We'd expect the final one to say "file:CONTENT" but _without_ a "converting" line. But it still runs the textconv script!

The problem is that the cache uses the blob id of the source as its key. But since we're grepping files in the working directory, they don't have an object id at all. If we grep in the tree, it works as expected:

  $ git -c diff.foo.cachetextconv=true grep --textconv . HEAD -- file
  converting...
  HEAD:file:CONTENT
  $ git -c diff.foo.cachetextconv=true grep --textconv . HEAD -- file
  HEAD:file:CONTENT

All of this textconv stuff was originally designed for the diff infrastructure. Even when it's diffing files, if they're tracked in the repository the diff code will pull the oid from the index (assuming the file is stat-clean). But the grep code doesn't do that (and I doubt that it matters for anything at all except this textconv caching feature).

It's probably possible to teach the grep code to do the same check-in-the-index trick, but I'm not sure how complicated it would be.

-Peff
Previous: Zach RiggleNext: Junio C Hamano
Message 4 of 7 in “git grep --threads 12 --textconv is effectively single-threaded”
  1. Zach RiggleJul 7, 2020
  2. Jeff KingJul 7, 2020
  3. Zach RiggleJul 8, 2020
  4. Jeff KingJul 8, 2020
  5. Junio C HamanoJul 8, 2020
  6. Jeff KingJul 9, 2020
  7. Junio C HamanoJul 10, 2020

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.