git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [TopGit PATCH v2] tg-create.sh: Support for multiple {to,cc,bcc} options
@ 2008-08-09 18:48 Bert Wesarg
  2008-08-11 20:47 ` Petr Baudis
  0 siblings, 1 reply; 3+ messages in thread
From: Bert Wesarg @ 2008-08-09 18:48 UTC (permalink / raw)
  To: Petr Baudis; +Cc: Bert Wesarg, git

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

New in v2:
Print a RFC2822 compliant header.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>

---
 tg-create.sh |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/tg-create.sh b/tg-create.sh
index 6cce7ed..d7ee1d2 100644
--- a/tg-create.sh
+++ b/tg-create.sh
@@ -100,13 +100,42 @@ git checkout -b "$name"
 echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps"
 git add "$root_dir/.topdeps"
 
+# Print a RFC2822 compliant header ($2) with values from the config option
+# ($1 without the topgit. prefix)
+get_multi_config()
+{
+	# Do we need to escape it for awk double quotes?
+	prefix="$2"
+	prefix_align="$(printf "%*s  " "${#2}" "")"
+
+	git config --get-all topgit.$1 |
+		awk '
+			BEGIN {
+				line = ""
+				prefix = "'"$prefix"': "
+			}
+				{
+					if (line != "") {
+						print prefix line ","
+						prefix = "'"$prefix_align"'"
+					}
+					line = $0
+				}
+			END {
+				if (line != "") {
+					print prefix line
+				}
+			}
+		'
+}
+
 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: (2e5b885..) t/support-for-multiple-to-cc-bcc-options (depends on: master)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-08-12  5:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-09 18:48 [TopGit PATCH v2] tg-create.sh: Support for multiple {to,cc,bcc} options Bert Wesarg
2008-08-11 20:47 ` Petr Baudis
2008-08-12  5:14   ` Bert Wesarg

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).