git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@strlen.de>
To: git@vger.kernel.org
Subject: [PATCH] [TOPGIT] Use git-mailinfo to extract author informations from .topmsg
Date: Fri, 19 Sep 2008 23:27:57 +0200	[thread overview]
Message-ID: <1221859677-8558-1-git-send-email-ukleinek@strlen.de> (raw)

This has the benefit that the [PATCH] prefixes are stripped and so it
might help to prevent you sending mails with two prefixes.  (As happend
to me after I git-format-patch'd an exported series and sent it out with
git-send-email.)

Moreover it should make the code more robust and it allows to remove a
helper function.
And it allows you to set add a Date: line to .topmsg which is then used
as author date.

Signed-off-by: Uwe Kleine-König <ukleinek@strlen.de>
---
 tg-export.sh |   45 +++++++++++++--------------------------------
 1 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/tg-export.sh b/tg-export.sh
index 654b38b..335f698 100644
--- a/tg-export.sh
+++ b/tg-export.sh
@@ -38,17 +38,6 @@ trap 'rm -rf "$playground"' EXIT
 
 ## Collapse driver
 
-# Trusty Cogito code:
-load_author()
-{
-	if [ -z "$GIT_AUTHOR_NAME" ] && echo "$1" | grep -q '^[^< ]'; then
-		export GIT_AUTHOR_NAME="$(echo "$1" | sed 's/ *<.*//')"
-	fi
-	if [ -z "$GIT_AUTHOR_EMAIL" ] && echo "$1" | grep -q '<.*>'; then
-		export GIT_AUTHOR_EMAIL="$(echo "$1" | sed 's/.*<\(.*\)>.*/\1/')"
-	fi
-}
-
 # pretty_tree NAME
 # Output tree ID of a cleaned-up tree without tg's artifacts.
 pretty_tree()
@@ -69,19 +58,16 @@ collapsed_commit()
 	>"$playground/^body"
 
 	# Get commit message and authorship information
-	git cat-file blob "$name:.topmsg" >"$playground/^msg"
-	while read line; do
-		if [ -z "$line" ]; then
-			# end of header
-			cat >"$playground/^body"
-			break
-		fi
-		case "$line" in
-		From:*) load_author "${line#From: }";;
-		Subject:*) echo "${line#Subject: }" >>"$playground/^pre";;
-		*) echo "$line" >>"$playground/^post";;
-		esac
-	done <"$playground/^msg"
+	git cat-file blob "$name:.topmsg" | git mailinfo "$playground/^msg" /dev/null > "$playground/^info"
+
+	GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$playground/^info")"
+	GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$playground/^info")"
+	GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$playground/^info")"
+	SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$playground/^info")"
+
+	test -n "$GIT_AUTHOR_NAME" && export GIT_AUTHOR_NAME
+	test -n "$GIT_AUTHOR_EMAIL" && export GIT_AUTHOR_EMAIL
+	test -n "$GIT_AUTHOR_DATE" && export GIT_AUTHOR_DATE
 
 	# Determine parent
 	parent="$(cut -f 1 "$playground/$name^parents")"
@@ -95,14 +81,9 @@ collapsed_commit()
 			$(for p in $parent; do echo -p $p; done))"
 	fi
 
-	{
-		if [ -s "$playground/^pre" ]; then
-			cat "$playground/^pre"
-			echo
-		fi
-		cat "$playground/^body"
-		[ ! -s "$playground/^post" ] || cat "$playground/^post"
-	} | git commit-tree "$(pretty_tree "$name")" -p "$parent"
+	(printf '%s\n\n' "$SUBJECT"; cat "$playground/^msg") |
+	git stripspace |
+	git commit-tree "$(pretty_tree "$name")" -p "$parent"
 
 	echo "$name" >>"$playground/^ticker"
 }
-- 
1.5.6.5

                 reply	other threads:[~2008-09-19 21:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1221859677-8558-1-git-send-email-ukleinek@strlen.de \
    --to=ukleinek@strlen.de \
    --cc=git@vger.kernel.org \
    /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).