git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits
@ 2009-02-10 13:48 Pat Notz
  2009-02-10 15:46 ` Jakub Narebski
  0 siblings, 1 reply; 6+ messages in thread
From: Pat Notz @ 2009-02-10 13:48 UTC (permalink / raw)
  To: git; +Cc: Pat Notz

In the show_new_revisions function, the original code:

   git rev-parse --not --branches | grep -v $(git rev-parse $refname) |

isn't quite right since one can create a new branch and push it without
any new commits.  In that case, two refs will have the same sha1 but
both would get filtered by the 'grep'.  In the end, we'll show ALL the
history which is not what we want.  Instead, we should list the branches
by name and remove the branch being updated and THEN pass that list
through rev-parse.

Signed-off-by: Pat Notz <pknotz@sandia.gov>
---
 contrib/hooks/post-receive-email |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 28a3c0e..116f89c 100644
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -615,7 +615,9 @@ show_new_revisions()
 		revspec=$oldrev..$newrev
 	fi
 
-	git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+	this_branch=$(echo $refname | sed 's@refs/heads/@@')
+	other_branches=$(git branch | sed 's/\*//g' | grep -v $this_branch)
+	git rev-parse --not $other_branches |
 	if [ -z "$custom_showrev" ]
 	then
 		git rev-list --pretty --stdin $revspec
-- 
1.6.1.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits
  2009-02-10 13:48 [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits Pat Notz
@ 2009-02-10 15:46 ` Jakub Narebski
  2009-02-10 15:59   ` Johannes Schindelin
  2009-02-10 16:30   ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: Jakub Narebski @ 2009-02-10 15:46 UTC (permalink / raw)
  To: Pat Notz; +Cc: git

"Pat Notz" <pknotz@sandia.gov> writes:

> In the show_new_revisions function, the original code:
> 
>    git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
> 
> isn't quite right since one can create a new branch and push it without
> any new commits.  In that case, two refs will have the same sha1 but
> both would get filtered by the 'grep'.  In the end, we'll show ALL the
> history which is not what we want.  Instead, we should list the branches
> by name and remove the branch being updated and THEN pass that list
> through rev-parse.

Good idea, bad execution.

> 
> Signed-off-by: Pat Notz <pknotz@sandia.gov>
> ---
>  contrib/hooks/post-receive-email |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
> index 28a3c0e..116f89c 100644
> --- a/contrib/hooks/post-receive-email
> +++ b/contrib/hooks/post-receive-email
> @@ -615,7 +615,9 @@ show_new_revisions()
>  		revspec=$oldrev..$newrev
>  	fi
>  
> -	git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
> +	this_branch=$(echo $refname | sed 's@refs/heads/@@')
> +	other_branches=$(git branch | sed 's/\*//g' | grep -v $this_branch)

git-branch is porcelain, git-branch is porcelain, git-branch is porcelain,
git-branch is porcelain, git-branch is porcelain, git-branch is porcelain,
git-branch is porcelain, git-branch is porcelain, ...

Don't use sed if shell will suffice...

Either:

+	this_branch=$refname
+	other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
+               grep -v $this_branch)

or

+	this_branch=${refname#refs/heads/}
...

> +	git rev-parse --not $other_branches |
>  	if [ -z "$custom_showrev" ]
>  	then
>  		git rev-list --pretty --stdin $revspec
> -- 
> 1.6.1.2
> 
> 

-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits
  2009-02-10 15:46 ` Jakub Narebski
@ 2009-02-10 15:59   ` Johannes Schindelin
  2009-02-10 16:30   ` Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Johannes Schindelin @ 2009-02-10 15:59 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Pat Notz, git

Hi,

On Tue, 10 Feb 2009, Jakub Narebski wrote:

> "Pat Notz" <pknotz@sandia.gov> writes:
> 
> > In the show_new_revisions function, the original code:
> > 
> >    git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
> > 
> > isn't quite right since one can create a new branch and push it without
> > any new commits.  In that case, two refs will have the same sha1 but
> > both would get filtered by the 'grep'.  In the end, we'll show ALL the
> > history which is not what we want.  Instead, we should list the branches
> > by name and remove the branch being updated and THEN pass that list
> > through rev-parse.
> 
> Good idea, bad execution.

And I thought that I hold the patent for grumpy comments on this list :-)

As for your suggestions, I think they are valid.  We try to keep the 
interface of certain commands (so called "plumbing") stable, for script 
consumption.  "git for-each-ref" is such a command.

However, "git branch" is meant for human consumption, and a pretty recent 
patch wants to change the interface to make it even friendlier -- but 
breaking scripts' assumption in the process, should they use "git branch".

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Fix contrib/hooks/post-receive-email for new duplicate branch
@ 2009-02-10 16:18 Pat Notz
  0 siblings, 0 replies; 6+ messages in thread
From: Pat Notz @ 2009-02-10 16:18 UTC (permalink / raw)
  To: git; +Cc: Pat Notz

In the show_new_revisions function, the original code:

  git rev-parse --not --branches | grep -v $(git rev-parse $refname) |

isn't quite right since one can create a new branch and push it
without any new commits.  In that case, two refs will have the same
sha1 but both would get filtered by the 'grep'.  In the end, we'll
show ALL the history which is not what we want.  Instead, we should
list the branches by name and remove the branch being updated and THEN
pass that list through rev-parse.

Revised as suggested by Jakub Narebski <jnareb@gmail.com> to use
git-for-each-ref instead of git-branch.  (Thanks!)

Signed-off-by: Pat Notz <pknotz@sandia.gov>
---
 contrib/hooks/post-receive-email |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 28a3c0e..ec52751 100644
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -615,7 +615,9 @@ show_new_revisions()
 		revspec=$oldrev..$newrev
 	fi
 
-	git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+	other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
+	    grep -v $refname)
+	git rev-parse --not $other_branches |
 	if [ -z "$custom_showrev" ]
 	then
 		git rev-list --pretty --stdin $revspec
-- 
1.6.1.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits
  2009-02-10 15:46 ` Jakub Narebski
  2009-02-10 15:59   ` Johannes Schindelin
@ 2009-02-10 16:30   ` Junio C Hamano
  2009-02-10 16:43     ` [PATCH] Fix contrib/hooks/post-receive-email for new duplicate branch Pat Notz
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2009-02-10 16:30 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Pat Notz, git

Jakub Narebski <jnareb@gmail.com> writes:

> +	this_branch=$refname
> +	other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
> +               grep -v $this_branch)

This is still not quite right.  grep -F -v "$this_branch" perhaps?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Fix contrib/hooks/post-receive-email for new duplicate branch
  2009-02-10 16:30   ` Junio C Hamano
@ 2009-02-10 16:43     ` Pat Notz
  0 siblings, 0 replies; 6+ messages in thread
From: Pat Notz @ 2009-02-10 16:43 UTC (permalink / raw)
  To: git; +Cc: Pat Notz

In the show_new_revisions function, the original code:

  git rev-parse --not --branches | grep -v $(git rev-parse $refname) |

isn't quite right since one can create a new branch and push it
without any new commits.  In that case, two refs will have the same
sha1 but both would get filtered by the 'grep'.  In the end, we'll
show ALL the history which is not what we want.  Instead, we should
list the branches by name and remove the branch being updated and THEN
pass that list through rev-parse.

Revised as suggested by Jakub Narebski and Junio C Hamano to use
git-for-each-ref instead of git-branch.  (Thanks!)

Signed-off-by: Pat Notz <pknotz@sandia.gov>
---
 contrib/hooks/post-receive-email |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 28a3c0e..60cbab6 100644
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -615,7 +615,9 @@ show_new_revisions()
 		revspec=$oldrev..$newrev
 	fi
 
-	git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+	other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
+	    grep -F -v $refname)
+	git rev-parse --not $other_branches |
 	if [ -z "$custom_showrev" ]
 	then
 		git rev-list --pretty --stdin $revspec
-- 
1.6.1.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-02-10 16:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-10 13:48 [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits Pat Notz
2009-02-10 15:46 ` Jakub Narebski
2009-02-10 15:59   ` Johannes Schindelin
2009-02-10 16:30   ` Junio C Hamano
2009-02-10 16:43     ` [PATCH] Fix contrib/hooks/post-receive-email for new duplicate branch Pat Notz
  -- strict thread matches above, loose matches on Subject: below --
2009-02-10 16:18 Pat Notz

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).