Module: tools Branch: master Commit: 6d9043361e57b699a496a96004cfc6511e7745d5 URL: http://source.winehq.org/git/tools.git/?a=commit;h=6d9043361e57b699a496a9600...
Author: Alexandre Julliard julliard@winehq.org Date: Thu Jun 14 17:17:35 2007 +0200
git-notify: Add support for reading references from stdin to allow running as a post-receive hook.
---
git-notify | 77 +++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 50 insertions(+), 27 deletions(-)
diff --git a/git-notify b/git-notify index a2bf65d..df8d49e 100755 --- a/git-notify +++ b/git-notify @@ -28,6 +28,9 @@ use open ':utf8'; use Encode 'encode'; use Cwd 'realpath';
+binmode STDIN, ':utf8'; +binmode STDOUT, ':utf8'; + # some parameters you may want to change
# base URL of the gitweb repository browser (can be set with the -u option) @@ -121,7 +124,7 @@ sub parse_options() elsif ($arg eq '-d') { $debug++; } else { usage(); } } - if ($#ARGV != 2) { usage(); } + if (@ARGV && $#ARGV != 2) { usage(); } }
# send an email notification @@ -339,40 +342,60 @@ sub send_global_notice($$$) mail_notification($commitlist_address, "New commits on branch $ref", "text/plain; charset=UTF-8", @notice); }
-$repos_name = get_repos_name(); -parse_options(); +# send all the notices +sub send_all_notices($$$) +{ + my ($ref, $old_sha1, $new_sha1) = @_;
-# append repository path to URL -$gitweb_url .= "/$repos_name.git"; + $ref =~ s/^refs/heads///;
-my $ref = $ARGV[0]; -$ref =~ s/^refs/heads///; + if ($old_sha1 eq '0' x 40) # new ref + { + send_commit_notice( $ref, $new_sha1 ) if $commitlist_address; + return; + }
-if ($ARGV[1] eq '0' x 40) # new ref -{ - send_commit_notice( $ref, $ARGV[2] ); - exit 0; -} + my @commits = ();
-my @commits = (); + open LIST, "-|" or exec "git", "rev-list", "^$old_sha1", "$new_sha1", @exclude_list or die "cannot exec git-rev-list"; + while (<LIST>) + { + chomp; + die "invalid commit $_" unless /^[0-9a-f]{40}$/; + unshift @commits, $_; + } + close LIST;
-open LIST, "-|" or exec "git", "rev-list", "^$ARGV[1]", "$ARGV[2]", @exclude_list or die "cannot exec git-rev-list"; -while (<LIST>) -{ - chomp; - die "invalid commit $_" unless /^[0-9a-f]{40}$/; - unshift @commits, $_; + if (@commits > $max_individual_notices) + { + send_global_notice( $ref, $old_sha1, $new_sha1 ) if $commitlist_address; + return; + } + + foreach my $commit (@commits) + { + send_commit_notice( $ref, $commit ) if $commitlist_address; + send_cia_notice( $ref, $commit ) if $cia_project_name; + } } -close LIST;
-if (@commits > $max_individual_notices) +$repos_name = get_repos_name(); +parse_options(); + +# append repository path to URL +$gitweb_url .= "/$repos_name.git"; + +if (@ARGV) { - send_global_notice( $ref, $ARGV[1], $ARGV[2] ); - exit 0; + send_all_notices( $ARGV[0], $ARGV[1], $ARGV[2] ); } - -foreach my $commit (@commits) +else # read them from stdin { - send_commit_notice( $ref, $commit ) if $commitlist_address; - send_cia_notice( $ref, $commit ) if $cia_project_name; + while (<>) + { + chomp; + if (/^([0-9a-f]{40}) ([0-9a-f]{40}) (.*)$/) { send_all_notices( $3, $1, $2 ); } + } } + +exit 0;