git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: larsxschneider@gmail.com
Cc: git@vger.kernel.org, jehan@orb.com
Subject: Re: [PATCH] convert: legitimately disable clean/smudge filter with an empty override
Date: Sun, 24 Jan 2016 16:45:00 -0500	[thread overview]
Message-ID: <20160124214459.GA31091@sigill.intra.peff.net> (raw)
In-Reply-To: <1453638170-52041-1-git-send-email-larsxschneider@gmail.com>

On Sun, Jan 24, 2016 at 01:22:50PM +0100, larsxschneider@gmail.com wrote:

> From: Lars Schneider <larsxschneider@gmail.com>
> 
> A clean/smudge filter can be disabled if set to an empty string. However,
> Git will try to run the empty string as command which results in a error
> message per processed file.
> 
> Teach Git to consider an empty clean/smudge filter as legitimately disabled
> and do not print an error message.

That makes sense to me, as I do not think the empty filter name can
possibly do anything useful. You omitted the real motivation here, but I
know what it is from past discussions: you want to be able to
temporarily disable a filter with "git -c filter.foo.clean= ...". Which
I think makes it more immediately obvious that this is a useful thing to
have, and not just user error.

> diff --git a/convert.c b/convert.c
> index 814e814..58af965 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -786,7 +786,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
>  	struct conv_attrs ca;
> 
>  	convert_attrs(&ca, path);
> -	if (ca.drv) {
> +	if (ca.drv && ca.drv->clean && strlen(ca.drv->clean)) {
>  		filter = ca.drv->clean;
>  		required = ca.drv->required;
>  	}
> @@ -835,7 +835,7 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
>  	struct conv_attrs ca;
> 
>  	convert_attrs(&ca, path);
> -	if (ca.drv) {
> +	if (ca.drv && ca.drv->smudge && strlen(ca.drv->smudge)) {
>  		filter = ca.drv->smudge;
>  		required = ca.drv->required;
>  	}

This catches two calls, but I think there are others. What about
would_convert_to_git_filter_fd and convert_to_git_filter_fd?

Would it make more sense for apply_filter() to treat the empty string as
a noop, just as it does for NULL?

I.e.:


diff --git a/convert.c b/convert.c
index 814e814..02d5f1e 100644
--- a/convert.c
+++ b/convert.c
@@ -395,7 +395,7 @@ static int apply_filter(const char *path, const char *src, size_t len, int fd,
 	struct async async;
 	struct filter_params params;
 
-	if (!cmd)
+	if (!cmd || !*cmd)
 		return 0;
 
 	if (!dst)

which I think would cover all callers?

-Peff

  parent reply	other threads:[~2016-01-24 21:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-24 12:22 [PATCH] convert: legitimately disable clean/smudge filter with an empty override larsxschneider
2016-01-24 15:06 ` Torsten Bögershausen
2016-01-24 21:35   ` Eric Sunshine
2016-01-27  9:49     ` Lars Schneider
2016-01-27  9:42   ` Lars Schneider
2016-01-24 21:45 ` Jeff King [this message]
2016-01-27  9:50   ` Lars Schneider
2016-01-25  1:25 ` Junio C Hamano
2016-01-28  9:27   ` Lars Schneider
2016-01-28 22:06     ` Junio C Hamano
2016-01-28 23:51 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160124214459.GA31091@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=jehan@orb.com \
    --cc=larsxschneider@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).