{"thread":{"id":"17697","subject":"[PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits","startedAt":"2009-02-10T13:48:15Z","lastAt":"2009-02-10T16:43:30Z","messageCount":5,"participants":["Pat Notz","Jakub Narebski","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"104008","messageId":"1234273695-4981-1-git-send-email-pknotz@sandia.gov","threadId":"17697","inReplyTo":null,"subject":"[PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits","fromName":"Pat Notz","fromEmail":"pknotz@sandia.gov","sentAt":"2009-02-10T13:48:15Z","receivedAt":"2009-02-10T13:48:15Z","isPatch":true,"sender":{"key":"patnotz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45364?v=4"},"body":"In the show_new_revisions function, the original code:\n\n   git rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n\nisn't quite right since one can create a new branch and push it without\nany new commits.  In that case, two refs will have the same sha1 but\nboth would get filtered by the 'grep'.  In the end, we'll show ALL the\nhistory which is not what we want.  Instead, we should list the branches\nby name and remove the branch being updated and THEN pass that list\nthrough rev-parse.\n\nSigned-off-by: Pat Notz <pknotz@sandia.gov>\n---\n contrib/hooks/post-receive-email |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 28a3c0e..116f89c 100644\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -615,7 +615,9 @@ show_new_revisions()\n \t\trevspec=$oldrev..$newrev\n \tfi\n \n-\tgit rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n+\tthis_branch=$(echo $refname | sed 's@refs/heads/@@')\n+\tother_branches=$(git branch | sed 's/\\*//g' | grep -v $this_branch)\n+\tgit rev-parse --not $other_branches |\n \tif [ -z \"$custom_showrev\" ]\n \tthen\n \t\tgit rev-list --pretty --stdin $revspec\n-- \n1.6.1.2\n"},{"id":"104026","messageId":"m3ab8uuwfg.fsf@localhost.localdomain","threadId":"17697","inReplyTo":"1234273695-4981-1-git-send-email-pknotz@sandia.gov","subject":"Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-02-10T15:46:31Z","receivedAt":"2009-02-10T15:46:31Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Pat Notz\" <pknotz@sandia.gov> writes:\n\n> In the show_new_revisions function, the original code:\n> \n>    git rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n> \n> isn't quite right since one can create a new branch and push it without\n> any new commits.  In that case, two refs will have the same sha1 but\n> both would get filtered by the 'grep'.  In the end, we'll show ALL the\n> history which is not what we want.  Instead, we should list the branches\n> by name and remove the branch being updated and THEN pass that list\n> through rev-parse.\n\nGood idea, bad execution.\n\n> \n> Signed-off-by: Pat Notz <pknotz@sandia.gov>\n> ---\n>  contrib/hooks/post-receive-email |    4 +++-\n>  1 files changed, 3 insertions(+), 1 deletions(-)\n> \n> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n> index 28a3c0e..116f89c 100644\n> --- a/contrib/hooks/post-receive-email\n> +++ b/contrib/hooks/post-receive-email\n> @@ -615,7 +615,9 @@ show_new_revisions()\n>  \t\trevspec=$oldrev..$newrev\n>  \tfi\n>  \n> -\tgit rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n> +\tthis_branch=$(echo $refname | sed 's@refs/heads/@@')\n> +\tother_branches=$(git branch | sed 's/\\*//g' | grep -v $this_branch)\n\ngit-branch is porcelain, git-branch is porcelain, git-branch is porcelain,\ngit-branch is porcelain, git-branch is porcelain, git-branch is porcelain,\ngit-branch is porcelain, git-branch is porcelain, ...\n\nDon't use sed if shell will suffice...\n\nEither:\n\n+\tthis_branch=$refname\n+\tother_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |\n+               grep -v $this_branch)\n\nor\n\n+\tthis_branch=${refname#refs/heads/}\n...\n\n> +\tgit rev-parse --not $other_branches |\n>  \tif [ -z \"$custom_showrev\" ]\n>  \tthen\n>  \t\tgit rev-list --pretty --stdin $revspec\n> -- \n> 1.6.1.2\n> \n> \n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"104030","messageId":"alpine.DEB.1.00.0902101655500.10279@pacific.mpi-cbg.de","threadId":"17697","inReplyTo":"m3ab8uuwfg.fsf@localhost.localdomain","subject":"Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-10T15:59:38Z","receivedAt":"2009-02-10T15:59:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 10 Feb 2009, Jakub Narebski wrote:\n\n> \"Pat Notz\" <pknotz@sandia.gov> writes:\n> \n> > In the show_new_revisions function, the original code:\n> > \n> >    git rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n> > \n> > isn't quite right since one can create a new branch and push it without\n> > any new commits.  In that case, two refs will have the same sha1 but\n> > both would get filtered by the 'grep'.  In the end, we'll show ALL the\n> > history which is not what we want.  Instead, we should list the branches\n> > by name and remove the branch being updated and THEN pass that list\n> > through rev-parse.\n> \n> Good idea, bad execution.\n\nAnd I thought that I hold the patent for grumpy comments on this list :-)\n\nAs for your suggestions, I think they are valid.  We try to keep the \ninterface of certain commands (so called \"plumbing\") stable, for script \nconsumption.  \"git for-each-ref\" is such a command.\n\nHowever, \"git branch\" is meant for human consumption, and a pretty recent \npatch wants to change the interface to make it even friendlier -- but \nbreaking scripts' assumption in the process, should they use \"git branch\".\n\nCiao,\nDscho\n"},{"id":"104034","messageId":"7vbptantj2.fsf@gitster.siamese.dyndns.org","threadId":"17697","inReplyTo":"m3ab8uuwfg.fsf@localhost.localdomain","subject":"Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-10T16:30:57Z","receivedAt":"2009-02-10T16:30:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> +\tthis_branch=$refname\n> +\tother_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |\n> +               grep -v $this_branch)\n\nThis is still not quite right.  grep -F -v \"$this_branch\" perhaps?\n"},{"id":"104037","messageId":"1234284210-7122-1-git-send-email-pknotz@sandia.gov","threadId":"17697","inReplyTo":"7vbptantj2.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Fix contrib/hooks/post-receive-email for new duplicate branch","fromName":"Pat Notz","fromEmail":"pknotz@sandia.gov","sentAt":"2009-02-10T16:43:30Z","receivedAt":"2009-02-10T16:43:30Z","isPatch":true,"sender":{"key":"patnotz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45364?v=4"},"body":"In the show_new_revisions function, the original code:\n\n  git rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n\nisn't quite right since one can create a new branch and push it\nwithout any new commits.  In that case, two refs will have the same\nsha1 but both would get filtered by the 'grep'.  In the end, we'll\nshow ALL the history which is not what we want.  Instead, we should\nlist the branches by name and remove the branch being updated and THEN\npass that list through rev-parse.\n\nRevised as suggested by Jakub Narebski and Junio C Hamano to use\ngit-for-each-ref instead of git-branch.  (Thanks!)\n\nSigned-off-by: Pat Notz <pknotz@sandia.gov>\n---\n contrib/hooks/post-receive-email |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 28a3c0e..60cbab6 100644\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -615,7 +615,9 @@ show_new_revisions()\n \t\trevspec=$oldrev..$newrev\n \tfi\n \n-\tgit rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n+\tother_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |\n+\t    grep -F -v $refname)\n+\tgit rev-parse --not $other_branches |\n \tif [ -z \"$custom_showrev\" ]\n \tthen\n \t\tgit rev-list --pretty --stdin $revspec\n-- \n1.6.1.2\n"}]}