From 539e437eaf86f1c9f6327b1c38d761c5f198f114 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 24 Sep 2010 16:24:53 +0200 Subject: properly implement authorinfo and committerinfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit authorinfo still lacks parsing .ubergit/author Signed-off-by: Uwe Kleine-König --- uglib.sh | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'uglib.sh') diff --git a/uglib.sh b/uglib.sh index 1c2398b..82f042d 100644 --- a/uglib.sh +++ b/uglib.sh @@ -1,10 +1,8 @@ ## authorinfo ## {{{2 authorinfo() { # XXX: implement parsing .ubergit/author - # more XXX: get author from $1 - echo "GIT_AUTHOR_NAME='Uwe Kleine-König'" - echo "GIT_AUTHER_EMAIL='ukl@pengutronix.de'" - echo "GIT_AUTHER_DATE='1283281597 +0200'" + + personfromcommit "$1" "author" "AUTHOR" } ## assert ## {{{2 @@ -32,10 +30,7 @@ commitenv() { committerinfo() { assert is_topic "$1" - # XXX: get commiter from $1 - echo "GIT_COMMITTER_NAME='Uwe Kleine-König'" - echo "GIT_COMMITTER_EMAIL='ukl@pengutronix.de'" - echo "GIT_COMMITTER_DATE='1283281597 +0200'" + personfromcommit "$1" "committer" "COMMITTER" } ## debug ## {{{2 @@ -143,6 +138,32 @@ msg() { git cat-file blob "$1:.ubergit/msg" } +## personfromcommit ## {{{2 +# personfromcommit [author|committer] [AUTHOR|COMMITTER] +personfromcommit() { + # inspired by git's get_author_ident_from_commit + local encoding script + + encoding="$(git config i18n.commitencoding || echo UTF-8)" + script=" + /^$2 /{ + s/'/'\\\\''/g # quote single quotes + h + s/^$2 \\([^<]*\\) <[^>]*> .*$/GIT_$3_NAME='\\1'/p + + g + s/^$2 [^<]* <\\([^>]*\\)> .*$/GIT_$3_EMAIL='\\1'/p + + g + s/^$2 [^<]* <[^>]*> \\(.*\\)$/GIT_$3_DATE='\\1'/p + + q + } + /^\$/q + " + git show -s --pretty=raw --encoding="$encoding" "$1" -- | sed -n -e "$script" +} + ## pretty_tree ## {{{2 pretty_tree() { git ls-tree --full-tree "$1" \ -- cgit v1.2.3