{"thread":{"id":"19734","subject":"[PATCH] contrib/hooks/post-receive-email: Fix solaris portability issues.","startedAt":"2009-06-08T07:02:37Z","lastAt":"2009-06-08T07:42:28Z","messageCount":2,"participants":["Thomas Moulard","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"115773","messageId":"1244444557-21685-1-git-send-email-thomas.moulard@gmail.com","threadId":"19734","inReplyTo":null,"subject":"[PATCH] contrib/hooks/post-receive-email: Fix solaris portability issues.","fromName":"Thomas Moulard","fromEmail":"thomas.moulard@gmail.com","sentAt":"2009-06-08T07:02:37Z","receivedAt":"2009-06-08T07:02:37Z","isPatch":true,"sender":{"key":"thomas.moulard@gmail.com","avatar":"https://gravatar.com/avatar/4396971c8087ce63f120744424ae346e88bf9bb537c3d7386f0751790890aa36?d=mp&s=160"},"body":"This patch solves some issues I had on a Solaris system:\n$ showrev -c /bin/sh | grep version\nCommand version: SunOS 5.10 Generic 121005-03 Oct 2006\n\n1. Replace $(...) by backquotes.\n2. Replace shell substitution ${var##word} by echo + sed\n3. Replace grep -F by fgrep.\n\nThese portability problems are reported in Autoconf documentation:\nhttp://www.gnu.org/software/hello/manual/autoconf/Shell-Substitutions.html#Shell-Substitutions\n\n---\n contrib/hooks/post-receive-email |   60 +++++++++++++++++++-------------------\n 1 files changed, 30 insertions(+), 30 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 2a66063..3d00475 100755\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -74,8 +74,8 @@\n generate_email()\n {\n \t# --- Arguments\n-\toldrev=$(git rev-parse $1)\n-\tnewrev=$(git rev-parse $2)\n+\toldrev=`git rev-parse $1`\n+\tnewrev=`git rev-parse $2`\n \trefname=\"$3\"\n\n \t# --- Interpret\n@@ -95,8 +95,8 @@ generate_email()\n \tfi\n\n \t# --- Get the revision types\n-\tnewrev_type=$(git cat-file -t $newrev 2> /dev/null)\n-\toldrev_type=$(git cat-file -t \"$oldrev\" 2> /dev/null)\n+\tnewrev_type=`git cat-file -t $newrev 2> /dev/null`\n+\toldrev_type=`git cat-file -t \"$oldrev\" 2> /dev/null`\n \tcase \"$change_type\" in\n \tcreate|update)\n \t\trev=\"$newrev\"\n@@ -118,12 +118,12 @@ generate_email()\n \t\trefs/tags/*,commit)\n \t\t\t# un-annotated tag\n \t\t\trefname_type=\"tag\"\n-\t\t\tshort_refname=${refname##refs/tags/}\n+\t\t\tshort_refname=`echo \"$refname\" | sed 's|refs/tags/||'`\n \t\t\t;;\n \t\trefs/tags/*,tag)\n \t\t\t# annotated tag\n \t\t\trefname_type=\"annotated tag\"\n-\t\t\tshort_refname=${refname##refs/tags/}\n+\t\t\tshort_refname=`echo \"$refname\" | sed 's|refs/tags/||'`\n \t\t\t# change recipients\n \t\t\tif [ -n \"$announcerecipients\" ]; then\n \t\t\t\trecipients=\"$announcerecipients\"\n@@ -132,12 +132,12 @@ generate_email()\n \t\trefs/heads/*,commit)\n \t\t\t# branch\n \t\t\trefname_type=\"branch\"\n-\t\t\tshort_refname=${refname##refs/heads/}\n+\t\t\tshort_refname=`echo \"$refname\" | sed 's|refs/heads/||'`\n \t\t\t;;\n \t\trefs/remotes/*,commit)\n \t\t\t# tracking branch\n \t\t\trefname_type=\"tracking branch\"\n-\t\t\tshort_refname=${refname##refs/remotes/}\n+\t\t\tshort_refname=`echo \"$refname\" | sed 's|refs/remotes/||'`\n \t\t\techo >&2 \"*** Push-update of tracking branch, $refname\"\n \t\t\techo >&2 \"***  - no email generated.\"\n \t\t\texit 0\n@@ -168,7 +168,7 @@ generate_email()\n \t# Email parameters\n \t# The email subject will contain the best description of the ref\n \t# that we can build from the parameters\n-\tdescribe=$(git describe $rev 2>/dev/null)\n+\tdescribe=`git describe $rev 2>/dev/null`\n \tif [ -z \"$describe\" ]; then\n \t\tdescribe=$rev\n \tfi\n@@ -279,7 +279,7 @@ generate_update_branch_email()\n \t# all of our commits.  What we really want is to exclude the current\n \t# value of $refname from the --not list, rather than N itself.  So:\n \t#\n-\t#  git rev-parse --not --all | grep -v $(git rev-parse $refname)\n+\t#  git rev-parse --not --all | grep -v `git rev-parse $refname`\n \t#\n \t# Get's us to something pretty safe (apart from the small time\n \t# between refname being read, and git rev-parse running - for that,\n@@ -320,9 +320,9 @@ generate_update_branch_email()\n \t# revisions\n \tfast_forward=\"\"\n \trev=\"\"\n-\tfor rev in $(git rev-list $newrev..$oldrev)\n+\tfor rev in `git rev-list $newrev..$oldrev`\n \tdo\n-\t\trevtype=$(git cat-file -t \"$rev\")\n+\t\trevtype=`git cat-file -t \"$rev\"`\n \t\techo \"  discards  $rev ($revtype)\"\n \tdone\n \tif [ -z \"$rev\" ]; then\n@@ -334,9 +334,9 @@ generate_update_branch_email()\n \t# have already had notification emails and is present to show the\n \t# full detail of the change from rolling back the old revision to\n \t# the base revision and then forward to the new revision\n-\tfor rev in $(git rev-list $oldrev..$newrev)\n+\tfor rev in `git rev-list $oldrev..$newrev`\n \tdo\n-\t\trevtype=$(git cat-file -t \"$rev\")\n+\t\trevtype=`git cat-file -t \"$rev\"`\n \t\techo \"       via  $rev ($revtype)\"\n \tdone\n\n@@ -357,7 +357,7 @@ generate_update_branch_email()\n\n \t\t# Find the common ancestor of the old and new revisions and\n \t\t# compare it with newrev\n-\t\tbaserev=$(git merge-base $oldrev $newrev)\n+\t\tbaserev=`git merge-base $oldrev $newrev`\n \t\trewind_only=\"\"\n \t\tif [ \"$baserev\" = \"$newrev\" ]; then\n \t\t\techo \"This update discarded existing revisions and left the branch pointing at\"\n@@ -460,12 +460,12 @@ generate_atag_email()\n {\n \t# Use git for-each-ref to pull out the individual fields from the\n \t# tag\n-\teval $(git for-each-ref --shell --format='\n+\teval `git for-each-ref --shell --format='\n \ttagobject=%(*objectname)\n \ttagtype=%(*objecttype)\n \ttagger=%(taggername)\n \ttagged=%(taggerdate)' $refname\n-\t)\n+\t`\n\n \techo \"   tagging  $tagobject ($tagtype)\"\n \tcase \"$tagtype\" in\n@@ -474,14 +474,14 @@ generate_atag_email()\n \t\t# If the tagged object is a commit, then we assume this is a\n \t\t# release, and so we calculate which tag this tag is\n \t\t# replacing\n-\t\tprevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)\n+\t\tprevtag=`git describe --abbrev=0 $newrev^ 2>/dev/null`\n\n \t\tif [ -n \"$prevtag\" ]; then\n \t\t\techo \"  replaces  $prevtag\"\n \t\tfi\n \t\t;;\n \t*)\n-\t\techo \"    length  $(git cat-file -s $tagobject) bytes\"\n+\t\techo \"    length  `git cat-file -s $tagobject` bytes\"\n \t\t;;\n \tesac\n \techo \" tagged by  $tagger\"\n@@ -578,7 +578,7 @@ generate_general_email()\n \t\t# a commit, so there is no log for us to display.  It's\n \t\t# probably not wise to output git cat-file as it could be a\n \t\t# binary blob.  We'll just say how big it is\n-\t\techo \"$newrev is a $newrev_type, and is $(git cat-file -s $newrev) bytes long.\"\n+\t\techo \"$newrev is a $newrev_type, and is `git cat-file -s $newrev` bytes long.\"\n \tfi\n }\n\n@@ -619,8 +619,8 @@ show_new_revisions()\n \t\trevspec=$oldrev..$newrev\n \tfi\n\n-\tother_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |\n-\t    grep -F -v $refname)\n+\tother_branches=`git for-each-ref --format='%(refname)' refs/heads/ |\n+\t    fgrep -v $refname`\n \tgit rev-parse --not $other_branches |\n \tif [ -z \"$custom_showrev\" ]\n \tthen\n@@ -629,7 +629,7 @@ show_new_revisions()\n \t\tgit rev-list --stdin $revspec |\n \t\twhile read onerev\n \t\tdo\n-\t\t\teval $(printf \"$custom_showrev\" $onerev)\n+\t\t\teval `printf \"$custom_showrev\" $onerev`\n \t\tdone\n \tfi\n }\n@@ -653,13 +653,13 @@ LOGEND=\"-----------------------------------------------------------------------\"\n # --- Config\n # Set GIT_DIR either from the working directory, or from the environment\n # variable.\n-GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)\n+GIT_DIR=`git rev-parse --git-dir 2>/dev/null`\n if [ -z \"$GIT_DIR\" ]; then\n \techo >&2 \"fatal: post-receive: GIT_DIR not set\"\n \texit 1\n fi\n\n-projectdesc=$(sed -ne '1p' \"$GIT_DIR/description\")\n+projectdesc=`sed -ne '1p' \"$GIT_DIR/description\"`\n # Check if the description is unchanged from it's default, and shorten it to\n # a more manageable length if it is\n if expr \"$projectdesc\" : \"Unnamed repository.*$\" >/dev/null\n@@ -667,11 +667,11 @@ then\n \tprojectdesc=\"UNNAMED PROJECT\"\n fi\n\n-recipients=$(git config hooks.mailinglist)\n-announcerecipients=$(git config hooks.announcelist)\n-envelopesender=$(git config hooks.envelopesender)\n-emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n-custom_showrev=$(git config hooks.showrev)\n+recipients=`git config hooks.mailinglist`\n+announcerecipients=`git config hooks.announcelist`\n+envelopesender=`git config hooks.envelopesender`\n+emailprefix=`git config hooks.emailprefix || echo '[SCM] '`\n+custom_showrev=`git config hooks.showrev`\n\n # --- Main loop\n # Allow dual mode: run from the command line just like the update hook, or\n--\n1.6.3\n"},{"id":"115777","messageId":"7v3aab6ujf.fsf@alter.siamese.dyndns.org","threadId":"19734","inReplyTo":"1244444557-21685-1-git-send-email-thomas.moulard@gmail.com","subject":"Re: [PATCH] contrib/hooks/post-receive-email: Fix solaris portability issues.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-08T07:42:28Z","receivedAt":"2009-06-08T07:42:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Moulard <thomas.moulard@gmail.com> writes:\n\n> This patch solves some issues I had on a Solaris system:\n> $ showrev -c /bin/sh | grep version\n> Command version: SunOS 5.10 Generic 121005-03 Oct 2006\n>\n> 1. Replace $(...) by backquotes.\n> 2. Replace shell substitution ${var##word} by echo + sed\n> 3. Replace grep -F by fgrep.\n\nThanks for trying to be helpful, but regrettably I have to say no.\n\nEarlier we already declared that any Bourne variant that does not\nunderstand $() is unfit to use with git as a general rule, but that\nparticular general rule was really meant to exclude broken /bin/sh on\nSolaris.  We recommend using either ksh or /usr/xpg4/bin/sh on that\nplatform.\n\nPerhaps SunOS 5.10 has a better /bin/sh than what people tried earlier,\nand with this patch everything start to magically work well on the\nplatform.  I however somehow doubt it.\n\nThere are tons of \"$()\" construct in our scripted Porcelain commands, and\nI think there are even nested ones that you cannot replace with \"``\"\nwithout introducing new variables and contaminating the namespace.\n\nEven though I am a traditionist, I personally would not want to see a\npatch to rewrite them back to ``, because that will force me to verify\nthat de-nesting of $(foo $(bar baz)) is done properly, that interaction\nbetween `` and double quotes are handled correctly, and that namespace\ncontamination does not have any ill effects, etc. etc.\n\n> @@ -118,12 +118,12 @@ generate_email()\n>  \t\trefs/tags/*,commit)\n>  \t\t\t# un-annotated tag\n>  \t\t\trefname_type=\"tag\"\n> -\t\t\tshort_refname=${refname##refs/tags/}\n> +\t\t\tshort_refname=`echo \"$refname\" | sed 's|refs/tags/||'`\n\nI think we used to write\n\n\tsed -e 's|^refs/tags/||'\n\nall over the place, but they were later replaced with \"${var#word}\".\n\nIn any case, this particular rewrite is wrong; you need to anchor the\npattern at the left end (so are other uses of 's|refs/xxx/||' in your\npatch).\n"}]}