From: Andy Parkins <andyparkins@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 3/4] update-hook: parse the tag header in preparation to use the tag type
Date: Tue, 20 Mar 2007 10:58:42 +0000 [thread overview]
Message-ID: <200703201058.42753.andyparkins@gmail.com> (raw)
The tag header is parsed with a while loop and read command. I'm not
entirely sure how portable it is, as it had to use the following unusual
heredoc format:
while read field value
do
# ..
done <<< "$(some command)"
This was necessary because piping the output to a while doesn't work
because the pipe is run in a separate process and hence setting
variables inside it has no effect in the main script process. This
"<<<" heredoc notation works around that problem, but I have no idea how
widely supported it is. The alternative (should it be necessary) is
to wastefully make multiple "git-cat-file | sed" calls - yuck.
This patch also updates the user/time extraction from the "tagger" field
to use the variable $tagger, rather than the "git-cat-file | sed" call
used previously.
Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
templates/hooks--update | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/templates/hooks--update b/templates/hooks--update
index 31e72ca..fd4c081 100644
--- a/templates/hooks--update
+++ b/templates/hooks--update
@@ -215,15 +215,33 @@ case "$refname_type" in
echo " from $oldrev"
fi
+ # Read the tag header
+ while read field value
+ do
+ case "$field" in
+ object)
+ tagobject="$value"
+ ;;
+ type)
+ tagtype="$value"
+ ;;
+ tag)
+ # Confirm that this tag has the right name? Nah
+ ;;
+ tagger)
+ tagger="$value"
+ ;;
+ esac
+ done <<< "$(git cat-file tag $newrev | head -q -n 4)"
+
# If this tag succeeds another, then show which tag it replaces
prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)
if [ -n "$prevtag" ]; then
echo " replaces $prevtag"
fi
- # Read the tag details
- eval $(git cat-file tag $newrev | \
- sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p')
+ # Extract user and time from tagger variable
+ eval $(sed -n 's/\([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p' <<< "$tagger")
tagged=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$DATEFORMAT")
echo " tagged by $tagger"
--
1.5.0.3.402.g0c48
next reply other threads:[~2007-03-20 10:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-20 10:58 Andy Parkins [this message]
2007-03-20 14:38 ` [PATCH 3/4] update-hook: parse the tag header in preparation to use the tag type Shawn O. Pearce
2007-03-20 15:24 ` Andy Parkins
2007-03-20 15:38 ` Shawn O. Pearce
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=200703201058.42753.andyparkins@gmail.com \
--to=andyparkins@gmail.com \
--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).