Re: [PATCH] filter-branch: pass tag name via stdin without newline

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Eric N. Vander Weele" <ericvw@xxxxxxxxx> writes:

> "git filter-branch --tag-name-filter" fails when the user-provided
> command attempts to trivially append text to the originally tag name,
> passed via stdin, due to an unexpected newline ('\n').  The newline is
> introduced due to "echo" piping the original tag name to the
> user-provided tag name filter command.

Is there any other place where we feed such an incomplete line
(i.e. a line without the terminating LF) to the filters in this
command?

I am guessing that the answer to that question would be no, and all
existing scripts by users expect the newline at the end of each
line.  So I would have to say that "due to an unexpected newline" is
a misleading statement--isn't it a bug in your filter that it did
not expect one?

> The only portable usage of "echo" is without any options and escape
> sequences.  Therefore, replacing "echo" with "printf" is a suitable,
> POSIX compliant alternative.

Yes, if we wanted to emit an incomplete line, we would be using

    printf "%s" "$var"

instead of

    echo -n "$var"

for portability.  But that would not belong to the log message for
this patch.  If the patch were to correct a script that originally
used "echo -n" to produce an incomplete line to instead use "printf",
these three lines would have been a perfect log message.

Thanks.

> Signed-off-by: Eric N. Vander Weele <ericvw@xxxxxxxxx>
> ---
>  git-filter-branch.sh     | 2 +-
>  t/t7003-filter-branch.sh | 5 +++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index 98f1779..949cd30 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -503,7 +503,7 @@ if [ "$filter_tag_name" ]; then
>  		new_sha1="$(cat "../map/$sha1")"
>  		GIT_COMMIT="$sha1"
>  		export GIT_COMMIT
> -		new_ref="$(echo "$ref" | eval "$filter_tag_name")" ||
> +		new_ref="$(printf "$ref" | eval "$filter_tag_name")" ||
>  			die "tag name filter failed: $filter_tag_name"
>  
>  		echo "$ref -> $new_ref ($sha1 -> $new_sha1)"
> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
> index 869e0bf..0db6808 100755
> --- a/t/t7003-filter-branch.sh
> +++ b/t/t7003-filter-branch.sh
> @@ -269,6 +269,11 @@ test_expect_success 'Tag name filtering retains tag message' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'Tag name filter does not pass tag ref with newline' '
> +	git filter-branch -f --tag-name-filter "cat && printf "_append"" -- A &&
> +	git rev-parse A_append > /dev/null 2>&1
> +'
> +
>  faux_gpg_tag='object XXXXXX
>  type commit
>  tag S
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]