[BUG] git log -S not respecting --no-textconv

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

[BUG] git log -S not respecting --no-textconv

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:56:37

Hi,

It seems the command "git log --no-textconv -Sfoo" still runs the
textconv filter (noticed because I have a broken textconv filter that
lets "git log -S" error out).

Steps to reproduce:

Create a repo with *.txt file(s) in it
$ echo '*.txt diff=wrong' > .gitattributes

An incorrect textconv filter errors out as expected:

$ git -c diff.wrong.textconv='xxx' log -Sfoo 
error: cannot run xxx: No such file or directory
fatal: unable to read files to diff

but --no-textconv has no effect:

$ git -c diff.wrong.textconv='xxx' log --no-textconv -Sfoo
error: cannot run xxx: No such file or directory
fatal: unable to read files to diff

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

[PATCH 1/2] diffcore-pickaxe: respect --no-textconv

From: Simon Ruderich <hidden>
Date: 2016-06-15 22:56:40

git log -S doesn't respect --no-textconv:

    $ echo '*.txt diff=wrong' > .gitattributes
    $ git -c diff.wrong.textconv='xxx' log --no-textconv -Sfoo
    error: cannot run xxx: No such file or directory
    fatal: unable to read files to diff

Signed-off-by: Simon Ruderich <redacted>
Reported-by: Matthieu Moy <redacted>
---
On Thu, Apr 04, 2013 at 10:34:17AM +0200, Matthieu Moy wrote:
Hi,

It seems the command "git log --no-textconv -Sfoo" still runs the
textconv filter (noticed because I have a broken textconv filter that
lets "git log -S" error out).

[snip]
Hello Matthieu,

This patch should fix it. All tests pass.

Regards
Simon

 diffcore-pickaxe.c     | 15 ++++++++++++---
 t/t4209-log-pickaxe.sh | 14 ++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index b097fa7..f814a52 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -78,7 +78,6 @@ static void fill_one(struct diff_filespec *one,
 		     mmfile_t *mf, struct userdiff_driver **textconv)
 {
 	if (DIFF_FILE_VALID(one)) {
-		*textconv = get_textconv(one);
 		mf->size = fill_textconv(*textconv, one, &mf->ptr);
 	} else {
 		memset(mf, 0, sizeof(*mf));
@@ -97,6 +96,11 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
 	if (diff_unmodified_pair(p))
 		return 0;
 
+	if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
+		textconv_one = get_textconv(p->one);
+		textconv_two = get_textconv(p->two);
+	}
+
 	fill_one(p->one, &mf1, &textconv_one);
 	fill_one(p->two, &mf2, &textconv_two);
 
@@ -201,14 +205,19 @@ static unsigned int contains(mmfile_t *mf, struct diff_options *o,
 static int has_changes(struct diff_filepair *p, struct diff_options *o,
 		       regex_t *regexp, kwset_t kws)
 {
-	struct userdiff_driver *textconv_one = get_textconv(p->one);
-	struct userdiff_driver *textconv_two = get_textconv(p->two);
+	struct userdiff_driver *textconv_one = NULL;
+	struct userdiff_driver *textconv_two = NULL;
 	mmfile_t mf1, mf2;
 	int ret;
 
 	if (!o->pickaxe[0])
 		return 0;
 
+	if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
+		textconv_one = get_textconv(p->one);
+		textconv_two = get_textconv(p->two);
+	}
+
 	/*
 	 * If we have an unmodified pair, we know that the count will be the
 	 * same and don't even have to load the blobs. Unless textconv is in
diff --git a/t/t4209-log-pickaxe.sh b/t/t4209-log-pickaxe.sh
index eed7273..953cec8 100755
--- a/t/t4209-log-pickaxe.sh
+++ b/t/t4209-log-pickaxe.sh
@@ -116,4 +116,18 @@ test_expect_success 'log -S -i (nomatch)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'log -S --textconv (missing textconv tool)' '
+	echo "* diff=test" >.gitattributes &&
+	test_must_fail git -c diff.test.textconv=missing log -Sfoo &&
+	rm .gitattributes
+'
+
+test_expect_success 'log -S --no-textconv (missing textconv tool)' '
+	echo "* diff=test" >.gitattributes &&
+	git -c diff.test.textconv=missing log -Sfoo --no-textconv >actual &&
+	>expect &&
+	test_cmp expect actual &&
+	rm .gitattributes
+'
+
 test_done
-- 
1.8.2

-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

Re: [PATCH 1/2] diffcore-pickaxe: respect --no-textconv

From: Jeff King <hidden>
Date: 2016-06-15 22:56:41

On Thu, Apr 04, 2013 at 06:03:59PM +0200, Simon Ruderich wrote:
git log -S doesn't respect --no-textconv:

    $ echo '*.txt diff=wrong' > .gitattributes
    $ git -c diff.wrong.textconv='xxx' log --no-textconv -Sfoo
    error: cannot run xxx: No such file or directory
    fatal: unable to read files to diff

Signed-off-by: Simon Ruderich <redacted>
Reported-by: Matthieu Moy <redacted>
Usually these pseudo-headers are meant to be chronological, so you would
swap the order.
quoted
It seems the command "git log --no-textconv -Sfoo" still runs the
textconv filter (noticed because I have a broken textconv filter that
lets "git log -S" error out).

[snip]
Hello Matthieu,

This patch should fix it. All tests pass.
Thanks, the patch looks correct to me, although...
quoted hunk
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index b097fa7..f814a52 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -78,7 +78,6 @@ static void fill_one(struct diff_filespec *one,
 		     mmfile_t *mf, struct userdiff_driver **textconv)
 {
 	if (DIFF_FILE_VALID(one)) {
-		*textconv = get_textconv(one);
 		mf->size = fill_textconv(*textconv, one, &mf->ptr);
Dropping this is the right thing to do with the rest of your patch, but
like Matthieu, it took me a second to see why. Something like this
should probably go into the commit message:

  We need to check that the ALLOW_TEXTCONV diff option is set before
  loading the textconv drivers. Rather than pass the diff options
  structure into the fill_one helper, let's just determine the textconv
  driver outside of that function and pass that in.

Though I really think that justification would make more sense if your
second cleanup patch came first, pulling the get_textconv calls back out
to the callers (which is easy to justify, since one of the callers
already has to load them itself _anyway_, which is just ugly).

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help