diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 09:44:29 (GMT) |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 09:44:29 (GMT) |
commit | 709d238041a590b42c598ee5099d252f4352c3c0 (patch) | |
tree | 0a7eec1cc632c809f45ce08fdf055d3cc31c0bf2 | |
parent | e31d34fc90c57d782bb82cd05ecb1ddda21b6d09 (diff) | |
download | monitoring-plugins-709d238041a590b42c598ee5099d252f4352c3c0.tar.gz |
git-notify: Call git-rev-list(1) via a subroutine
Add a subroutine which abstracts away executing git-rev-list(1) and
checking the result in order to avoid code duplication.
-rwxr-xr-x | tools/git-notify | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/tools/git-notify b/tools/git-notify index 848cfe0..6d5a564 100755 --- a/tools/git-notify +++ b/tools/git-notify | |||
@@ -102,6 +102,28 @@ sub xml_escape($) | |||
102 | return $str; | 102 | return $str; |
103 | } | 103 | } |
104 | 104 | ||
105 | # execute git-rev-list(1) with the given parameters and return the output | ||
106 | sub git_rev_list(@) | ||
107 | { | ||
108 | my @args = @_; | ||
109 | my $revlist = []; | ||
110 | my $pid = open REVLIST, "-|"; | ||
111 | |||
112 | die "Cannot open pipe: $!" if not defined $pid; | ||
113 | if (!$pid) | ||
114 | { | ||
115 | exec "git", "rev-list", @revlist_options, @args or die "Cannot execute rev-list: $!"; | ||
116 | } | ||
117 | while (<REVLIST>) | ||
118 | { | ||
119 | chomp; | ||
120 | die "Invalid commit: $_" if not /^[0-9a-f]{40}$/; | ||
121 | push @$revlist, $_; | ||
122 | } | ||
123 | close REVLIST or die $! ? "Cannot execute rev-list: $!" : "rev-list exited with status: $?"; | ||
124 | return $revlist; | ||
125 | } | ||
126 | |||
105 | # right-justify the left column of "left: right" elements, omit undefined elements | 127 | # right-justify the left column of "left: right" elements, omit undefined elements |
106 | sub format_table(@) | 128 | sub format_table(@) |
107 | { | 129 | { |
@@ -353,19 +375,14 @@ sub send_cia_notice($$) | |||
353 | sub send_global_notice($$$) | 375 | sub send_global_notice($$$) |
354 | { | 376 | { |
355 | my ($ref, $old_sha1, $new_sha1) = @_; | 377 | my ($ref, $old_sha1, $new_sha1) = @_; |
356 | my @notice = (); | 378 | my $notice = git_rev_list("--pretty", "^$old_sha1", "$new_sha1", @exclude_list); |
357 | 379 | ||
358 | push @revlist_options, "--pretty"; | 380 | foreach my $rev (@$notice) |
359 | open LIST, "-|" or exec "git", "rev-list", @revlist_options, "^$old_sha1", "$new_sha1", @exclude_list or die "cannot exec git-rev-list"; | ||
360 | while (<LIST>) | ||
361 | { | 381 | { |
362 | chomp; | 382 | $rev =~ s/^commit /URL: $gitweb_url\/?a=commit;h=/ if $gitweb_url; |
363 | s/^commit /URL: $gitweb_url\/?a=commit;h=/ if $gitweb_url; | ||
364 | push @notice, $_; | ||
365 | } | 383 | } |
366 | close LIST; | ||
367 | 384 | ||
368 | mail_notification($commitlist_address, "New commits on branch $ref", "text/plain; charset=UTF-8", @notice); | 385 | mail_notification($commitlist_address, "New commits on branch $ref", "text/plain; charset=UTF-8", @$notice); |
369 | } | 386 | } |
370 | 387 | ||
371 | # send all the notices | 388 | # send all the notices |