threads / patch / 14878

patchtg-create.sh: Support for multiple {to,cc,bcc} options

Subject: [TopGit PATCH] tg-create.sh: Support for multiple {to,cc,bcc} options

## tl;dr

6 messages between Aug 7, 2008 and Aug 9, 2008. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Bert Wesarg· Aug 7, 2008, 20:31 UTC · lore

Git config supports multiple values for the same config key, so support it for these TopGit config options, too.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 tg-create.sh |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
Show changes to tg-create.sh +14 −3
diff --git a/tg-create.sh b/tg-create.sh
index 6cce7ed..d47959b 100644
--- a/tg-create.sh
+++ b/tg-create.sh
@@ -100,13 +100,24 @@ git checkout -b "$name"
 echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps"
 git add "$root_dir/.topdeps"
 
+# Print each config value for a key ($1, without "topgit." prefix)
+# with the given prefix ($2)
+get_multi_config()
+{
+	# escape any / in prefix for sed
+	prefix="$(echo "$2" | sed -e 's/\//\\\\\//g')"
+
+	git config --get-all topgit.$1 2>/dev/null |
+		sed -e "s/^/$prefix /g"
+}
+
 author="$(git var GIT_AUTHOR_IDENT)"
 author_addr="${author%> *}>"
 {
 	echo "From: $author_addr"
-	! header="$(git config topgit.to)" || echo "To: $header"
-	! header="$(git config topgit.cc)" || echo "Cc: $header"
-	! header="$(git config topgit.bcc)" || echo "Bcc: $header"
+	get_multi_config to  "To:"
+	get_multi_config cc  "Cc:"
+	get_multi_config bcc "Bcc:"
 	! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix "
 	echo "Subject: [${subject_prefix}PATCH] $name"
 	echo
-- 
tg: (e311d15..) t/support-for-multiple-to-cc-bcc-options (depends on: master)
Petr Baudis· Aug 9, 2008, 00:33 UTC · re: Bert Wesarg · lore

Re: [TopGit PATCH] tg-create.sh: Support for multiple {to,cc,bcc} options

  Hi,
On Thu, Aug 07, 2008 at 10:31:26PM +0200, Bert Wesarg wrote:
Show 23 quoted lines
> Git config supports multiple values for the same config key, so support it
> for these TopGit config options, too.
> 
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> 
> ---
>  tg-create.sh |   17 ++++++++++++++---
>  1 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/tg-create.sh b/tg-create.sh
> index 6cce7ed..d47959b 100644
> --- a/tg-create.sh
> +++ b/tg-create.sh
> @@ -100,13 +100,24 @@ git checkout -b "$name"
>  echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps"
>  git add "$root_dir/.topdeps"
>  
> +# Print each config value for a key ($1, without "topgit." prefix)
> +# with the given prefix ($2)
> +get_multi_config()
> +{
> +	# escape any / in prefix for sed
> +	prefix="$(echo "$2" | sed -e 's/\//\\\\\//g')"
Maybe use s### ? ;-)
> +
> +	git config --get-all topgit.$1 2>/dev/null |
> +		sed -e "s/^/$prefix /g"
> +}

Won't this return an error code and terminate the script in case no option is defined? And why the stderr redirect?

Show 13 quoted lines
>  author="$(git var GIT_AUTHOR_IDENT)"
>  author_addr="${author%> *}>"
>  {
>  	echo "From: $author_addr"
> -	! header="$(git config topgit.to)" || echo "To: $header"
> -	! header="$(git config topgit.cc)" || echo "Cc: $header"
> -	! header="$(git config topgit.bcc)" || echo "Bcc: $header"
> +	get_multi_config to  "To:"
> +	get_multi_config cc  "Cc:"
> +	get_multi_config bcc "Bcc:"
>  	! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix "
>  	echo "Subject: [${subject_prefix}PATCH] $name"
>  	echo

One trouble here is that I've seen mailers mess up when there is multiple occurences of these headers, so it would be probably safer to concatenate them all to single line, comma-separated.

-- 
				Petr "Pasky" Baudis
The next generation of interesting software will be done
on the Macintosh, not the IBM PC.  -- Bill Gates
Junio C Hamano· Aug 9, 2008, 01:37 UTC · re: Petr Baudis · lore

Re: [TopGit PATCH] tg-create.sh: Support for multiple {to,cc,bcc} options

Petr Baudis <pasky@suse.cz> writes:
>> +	prefix="$(echo "$2" | sed -e 's/\//\\\\\//g')"
>
> Maybe use s### ? ;-)
Personally I like '|' instead.  It's much less visually distracting than #.
Show 7 quoted lines
>> +
>> +	git config --get-all topgit.$1 2>/dev/null |
>> +		sed -e "s/^/$prefix /g"
>> +}
>
> Won't this return an error code and terminate the script in case no
> option is defined?

Exit code from upstream of a pipe does not affect the exit code from the pipeline, and sed does not exit non-zero just because there was no substitution.

Show 13 quoted lines
>> -	! header="$(git config topgit.to)" || echo "To: $header"
>> -	! header="$(git config topgit.cc)" || echo "Cc: $header"
>> -	! header="$(git config topgit.bcc)" || echo "Bcc: $header"
>> +	get_multi_config to  "To:"
>> +	get_multi_config cc  "Cc:"
>> +	get_multi_config bcc "Bcc:"
>>  	! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix "
>>  	echo "Subject: [${subject_prefix}PATCH] $name"
>>  	echo
>
> One trouble here is that I've seen mailers mess up when there is
> multiple occurences of these headers, so it would be probably safer to
> concatenate them all to single line, comma-separated.

It is not just "I've seen mailers"; RFC2822 wants you to have at most one (see the table on Page 20).

Bert Wesarg· Aug 9, 2008, 07:23 UTC · re: Junio C Hamano · lore

Re: [TopGit PATCH] tg-create.sh: Support for multiple {to,cc,bcc} options

On Sat, Aug 9, 2008 at 03:37, Junio C Hamano <gitster@pobox.com> wrote:
Show 7 quoted lines
> Petr Baudis <pasky@suse.cz> writes:
>
>>> +    prefix="$(echo "$2" | sed -e 's/\//\\\\\//g')"
>>
>> Maybe use s### ? ;-)
>
> Personally I like '|' instead.  It's much less visually distracting than #.
  ^^^^^^^^^^ says it all ;-)
Show 8 quoted lines
>
>>> +
>>> +    git config --get-all topgit.$1 2>/dev/null |
>>> +            sed -e "s/^/$prefix /g"
>>> +}
>>
>> Won't this return an error code and terminate the script in case no
>> option is defined?

I tested it with none defined options: no error, no distracting empty lines, no error messages. so it worked here.

Show 16 quoted lines
>>> -    ! header="$(git config topgit.to)" || echo "To: $header"
>>> -    ! header="$(git config topgit.cc)" || echo "Cc: $header"
>>> -    ! header="$(git config topgit.bcc)" || echo "Bcc: $header"
>>> +    get_multi_config to  "To:"
>>> +    get_multi_config cc  "Cc:"
>>> +    get_multi_config bcc "Bcc:"
>>>      ! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix "
>>>      echo "Subject: [${subject_prefix}PATCH] $name"
>>>      echo
>>
>> One trouble here is that I've seen mailers mess up when there is
>> multiple occurences of these headers, so it would be probably safer to
>> concatenate them all to single line, comma-separated.
>
> It is not just "I've seen mailers"; RFC2822 wants you to have at most one
> (see the table on Page 20).

But do we generate a valid mail with tg patch, or just a patch file with some special looking lines? Anyway, I thought about the comma separated solution too, but git send-mail handles these multi lines well. So I take the easy road.

Bert
Petr Baudis· Aug 9, 2008, 08:27 UTC · re: Junio C Hamano · lore

Re: [TopGit PATCH] tg-create.sh: Support for multiple {to,cc,bcc} options

On Fri, Aug 08, 2008 at 06:37:13PM -0700, Junio C Hamano wrote:
Show 7 quoted lines
> Petr Baudis <pasky@suse.cz> writes:
> 
> >> +	prefix="$(echo "$2" | sed -e 's/\//\\\\\//g')"
> >
> > Maybe use s### ? ;-)
> 
> Personally I like '|' instead.  It's much less visually distracting than #.
I'm just used to '#' more, but either is fine for me.
Show 11 quoted lines
> >> +
> >> +	git config --get-all topgit.$1 2>/dev/null |
> >> +		sed -e "s/^/$prefix /g"
> >> +}
> >
> > Won't this return an error code and terminate the script in case no
> > option is defined?
> 
> Exit code from upstream of a pipe does not affect the exit code from the
> pipeline, and sed does not exit non-zero just because there was no
> substitution.

Oh, you're right - somehow I didn't quite absorb that pipe is used late at the night. ;-) I still don't understand the stderr redirect, though.

				Petr "Pasky" Baudis
Bert Wesarg· Aug 9, 2008, 10:49 UTC · re: Petr Baudis · lore

Re: [TopGit PATCH] tg-create.sh: Support for multiple {to,cc,bcc} options

On Sat, Aug 9, 2008 at 10:27, Petr Baudis <pasky@suse.cz> wrote:
Show 5 quoted lines
>> >> +
>> >> +  git config --get-all topgit.$1 2>/dev/null |
>> >> +          sed -e "s/^/$prefix /g"
>> >> +}
> I still don't understand the stderr redirect, though.
Just precaution, I think. It seems unnecessary.
Bert
>
>                                Petr "Pasky" Baudis
>

← back to recent threads