{"thread":{"id":"7329","subject":"[PATCH 3/4] update-hook: parse the tag header in preparation to use the tag type","startedAt":"2007-03-20T10:58:42Z","lastAt":"2007-03-20T15:38:15Z","messageCount":4,"participants":["Andy Parkins","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"37614","messageId":"200703201058.42753.andyparkins@gmail.com","threadId":"7329","inReplyTo":null,"subject":"[PATCH 3/4] update-hook: parse the tag header in preparation to use the tag type","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-03-20T10:58:42Z","receivedAt":"2007-03-20T10:58:42Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"The tag header is parsed with a while loop and read command.  I'm not\nentirely sure how portable it is, as it had to use the following unusual\nheredoc format:\n\n  while read field value\n  do\n    # ..\n  done <<< \"$(some command)\"\n\nThis was necessary because piping the output to a while doesn't work\nbecause the pipe is run in a separate process and hence setting\nvariables inside it has no effect in the main script process.  This\n\"<<<\" heredoc notation works around that problem, but I have no idea how\nwidely supported it is.  The alternative (should it be necessary) is\nto wastefully make multiple \"git-cat-file | sed\" calls - yuck.\n\nThis patch also updates the user/time extraction from the \"tagger\" field\nto use the variable $tagger, rather than the \"git-cat-file | sed\" call\nused previously.\n\nSigned-off-by: Andy Parkins <andyparkins@gmail.com>\n---\n templates/hooks--update |   24 +++++++++++++++++++++---\n 1 files changed, 21 insertions(+), 3 deletions(-)\n\ndiff --git a/templates/hooks--update b/templates/hooks--update\nindex 31e72ca..fd4c081 100644\n--- a/templates/hooks--update\n+++ b/templates/hooks--update\n@@ -215,15 +215,33 @@ case \"$refname_type\" in\n \t\t\techo \"      from  $oldrev\"\n \t\tfi\n \n+\t\t# Read the tag header\n+\t\twhile read field value\n+\t\tdo\n+\t\t\tcase \"$field\" in\n+\t\t\tobject)\n+\t\t\t\ttagobject=\"$value\"\n+\t\t\t\t;;\n+\t\t\ttype)\n+\t\t\t\ttagtype=\"$value\"\n+\t\t\t\t;;\n+\t\t\ttag)\n+\t\t\t\t# Confirm that this tag has the right name?  Nah\n+\t\t\t\t;;\n+\t\t\ttagger)\n+\t\t\t\ttagger=\"$value\"\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\tdone <<< \"$(git cat-file tag $newrev | head -q -n 4)\"\n+\n \t\t# If this tag succeeds another, then show which tag it replaces\n \t\tprevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)\n \t\tif [ -n \"$prevtag\" ]; then\n \t\t\techo \"  replaces  $prevtag\"\n \t\tfi\n \n-\t\t# Read the tag details\n-\t\teval $(git cat-file tag $newrev | \\\n-\t\t\tsed -n '4s/tagger \\([^>]*>\\)[^0-9]*\\([0-9]*\\).*/tagger=\"\\1\" ts=\"\\2\"/p')\n+\t\t# Extract user and time from tagger variable\n+\t\teval $(sed -n 's/\\([^>]*>\\)[^0-9]*\\([0-9]*\\).*/tagger=\"\\1\" ts=\"\\2\"/p' <<< \"$tagger\")\n \t\ttagged=$(date --date=\"1970-01-01 00:00:00 +0000 $ts seconds\" +\"$DATEFORMAT\")\n \n \t\techo \" tagged by  $tagger\"\n-- \n1.5.0.3.402.g0c48\n"},{"id":"37620","messageId":"20070320143844.GA1750@spearce.org","threadId":"7329","inReplyTo":"200703201058.42753.andyparkins@gmail.com","subject":"Re: [PATCH 3/4] update-hook: parse the tag header in preparation to use the tag type","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-20T14:38:44Z","receivedAt":"2007-03-20T14:38:44Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> wrote:\n> The tag header is parsed with a while loop and read command.  I'm not\n> entirely sure how portable it is, as it had to use the following unusual\n> heredoc format:\n> \n>   while read field value\n>   do\n>     # ..\n>   done <<< \"$(some command)\"\n\nTo bad you can't use for-each-ref.  ;-)\n\nThe problem of course is the update hook is running before a ref\nis created to point at the tag.  If you used post-receive hook\non the other hand...  Oh, right, that has its own problems too!\n\n-- \nShawn.\n"},{"id":"37623","messageId":"200703201524.04282.andyparkins@gmail.com","threadId":"7329","inReplyTo":"20070320143844.GA1750@spearce.org","subject":"Re: [PATCH 3/4] update-hook: parse the tag header in preparation to use the tag type","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-03-20T15:24:03Z","receivedAt":"2007-03-20T15:24:03Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Tuesday 2007 March 20 14:38, Shawn O. Pearce wrote:\n\n> The problem of course is the update hook is running before a ref\n> is created to point at the tag.  If you used post-receive hook\n> on the other hand...  Oh, right, that has its own problems too!\n\nI've obviously not described the problem very well; as I don't understand how \nyour comment relates to this patch.\n\nAll I'm doing is pulling the individual fields out of\n\n $ git cat-file -p v1.5.0\n object 437b1b20df4b356c9342dac8d38849f24ef44f27\n type commit\n tag v1.5.0\n tagger Junio C Hamano <junkio@cox.net> Wed Feb 14 00:00:00 2007 +0000\n\nAnd putting them in their own variables.  I'm not sure how for-each-ref or in \nfact, any ref-based tool would help me do this.  At this point it's nothing \nto do with git, it's a standard shell script problem.\n\n git cat-file -p $newrev | while read field value\n do\n   variable = \"found\"\n done\n echo $variable\n\nDoesn't work, because the right half of the pipe is run in its own process and \nso setting \"variable\" has no effect once the while loop is over.\n\nI found that \"<<<\" heredoc thing in the bash manual, which is almost like \nhaving a reverse pipe and allows the while loop to run in the main process.\n\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIET\nandyparkins@gmail.com\n"},{"id":"37627","messageId":"20070320153815.GD1750@spearce.org","threadId":"7329","inReplyTo":"200703201524.04282.andyparkins@gmail.com","subject":"Re: [PATCH 3/4] update-hook: parse the tag header in preparation to use the tag type","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-20T15:38:15Z","receivedAt":"2007-03-20T15:38:15Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> wrote:\n> On Tuesday 2007 March 20 14:38, Shawn O. Pearce wrote:\n> \n> > The problem of course is the update hook is running before a ref\n> > is created to point at the tag.  If you used post-receive hook\n> > on the other hand...  Oh, right, that has its own problems too!\n> \n> I've obviously not described the problem very well; as I don't understand how \n> your comment relates to this patch.\n> \n\neval `git for-each-ref --format='taggername=%(taggername) taggerdate=%(taggerdate)' thetag`\n\nThen you have $taggername and $taggerdate available.  ;-)\n\nThe problem is, there is no ref to for-each over.  :-(\n\n-- \nShawn.\n"}]}