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

Re: Bug: diff --no-index with cachetextconv crashes

From
Jeff King <peff@peff.net>
Date
Feb 26, 2024, 07:22 UTC
Message-ID
<20240226072248.GC780982@coredump.intra.peff.net>
In-Reply-To
<CACeVQwQ4MELjB8nZyeu9QDTtgwhhw0oOsL8BHdm_rxTj1vMy+A@mail.gmail.com>
On Mon, Feb 26, 2024 at 08:03:04AM +0100, Paweł Dominiak wrote:
> That's my first bug report for git and my first email to a mailing
> list in general, I hope for understanding :)
Hi, welcome, and thanks for a clear bug report. :)
Show 15 quoted lines
> [Steps to reproduce your issue]
> 
> Global .gitattributes:
> 
> *.txt diff=test
> 
> Global .gitconfig:
> 
> [diff "test"]
>     textconv = cat
>     cachetextconv = true
> 
> Called command:
> 
> git --no-pager diff --no-index foo.txt bar.txt

OK, I would say that this failing is semi-expected. :) The caching system works using "git notes", which are stored in refs in the repository. And since you are running "diff --no-index" outside of a repository, there is nowhere to put them.

And so this BUG call makes sense:
> BUG: refs.c:2095: attempting to get main_ref_store outside of repository

We tried to load notes but there's no ref store at all, and the low-level ref code caught this.

Of course any time we see a BUG something has gone wrong. What I think _should_ happen is that we should quietly disable the caching (which, after all, is just an optimization) and otherwise complete the command.

So we'd probably want something like this:
diff --git a/userdiff.c b/userdiff.c
index e399543823..fce3a31efa 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -3,6 +3,7 @@
 #include "userdiff.h"
 #include "attr.h"
 #include "strbuf.h"
+#include "environment.h"
 
 static struct userdiff_driver *drivers;
 static int ndrivers;
@@ -460,7 +461,8 @@ struct userdiff_driver *userdiff_get_textconv(struct repository *r,
 	if (!driver->textconv)
 		return NULL;
 
-	if (driver->textconv_want_cache && !driver->textconv_cache) {
+	if (driver->textconv_want_cache && !driver->textconv_cache &&
+	    have_git_dir()) {
 		struct notes_cache *c = xmalloc(sizeof(*c));
 		struct strbuf name = STRBUF_INIT;
 

-Peff
Previous: Paweł DominiakNext: Paweł Dominiak
Message 2 of 5 in “Bug: diff --no-index with cachetextconv crashes”
  1. Paweł DominiakFeb 26, 2024
  2. Jeff KingFeb 26, 2024
  3. Paweł DominiakFeb 26, 2024
  4. userdiff: skip textconv caching when not in a repositoryJeff King, Feb 26, 2024
  5. Junio C HamanoFeb 26, 2024

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.