diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 20:55:44 (GMT) |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 20:55:44 (GMT) |
commit | a6b329689782ddd22b4ecd52d0b375e0841ca682 (patch) | |
tree | 54bcd885c32dc4de0cdf8980ceb93b9bb5573925 /tools | |
parent | aa5dfec91726da8d9d4a4fa63f11c7b0da8c9401 (diff) | |
download | monitoring-plugins-a6b329689782ddd22b4ecd52d0b375e0841ca682.tar.gz |
git-nofity: Try to shorten Gitweb URLs
Instead of using the full SHA1 values of commit object names within
Gitweb URLs, try to abbreviate them to a shorter unique name.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/git-notify | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tools/git-notify b/tools/git-notify index a786f83..a158e87 100755 --- a/tools/git-notify +++ b/tools/git-notify | |||
@@ -168,6 +168,11 @@ sub format_table(@) | |||
168 | return @table; | 168 | return @table; |
169 | } | 169 | } |
170 | 170 | ||
171 | # return the gitweb URL of the given commit or undef | ||
172 | sub gitweb_url($$) | ||
173 | { | ||
174 | } | ||
175 | |||
171 | # format an integer date + timezone as string | 176 | # format an integer date + timezone as string |
172 | # algorithm taken from git's date.c | 177 | # algorithm taken from git's date.c |
173 | sub format_date($$) | 178 | sub format_date($$) |
@@ -317,6 +322,7 @@ sub send_commit_notice($$) | |||
317 | my ($ref,$obj) = @_; | 322 | my ($ref,$obj) = @_; |
318 | my %info = get_object_info($obj); | 323 | my %info = get_object_info($obj); |
319 | my @notice = (); | 324 | my @notice = (); |
325 | my $url; | ||
320 | 326 | ||
321 | open DIFF, "-|" or exec "git", "diff-tree", "-p", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree"; | 327 | open DIFF, "-|" or exec "git", "diff-tree", "-p", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree"; |
322 | my $diff = join("", <DIFF>); | 328 | my $diff = join("", <DIFF>); |
@@ -324,6 +330,17 @@ sub send_commit_notice($$) | |||
324 | 330 | ||
325 | return if length($diff) == 0; | 331 | return if length($diff) == 0; |
326 | 332 | ||
333 | if ($gitweb_url) | ||
334 | { | ||
335 | open REVPARSE, "-|" or exec "git", "rev-parse", "--short", $obj or die "cannot exec git-rev-parse"; | ||
336 | my $short_obj = <REVPARSE>; | ||
337 | close REVPARSE or die $! ? "Cannot execute rev-parse: $!" : "rev-parse exited with status: $?"; | ||
338 | |||
339 | $short_obj = $obj if not defined $short_obj; | ||
340 | chomp $short_obj; | ||
341 | $url = "$gitweb_url/?a=commit;h=$short_obj"; | ||
342 | } | ||
343 | |||
327 | push @notice, format_table( | 344 | push @notice, format_table( |
328 | "Module: $repos_name", | 345 | "Module: $repos_name", |
329 | "Branch: $ref", | 346 | "Branch: $ref", |
@@ -331,7 +348,7 @@ sub send_commit_notice($$) | |||
331 | "Author:" . $info{"author"}, | 348 | "Author:" . $info{"author"}, |
332 | $info{"committer"} ne $info{"author"} ? "Committer:" . $info{"committer"} : undef, | 349 | $info{"committer"} ne $info{"author"} ? "Committer:" . $info{"committer"} : undef, |
333 | "Date:" . format_date($info{"author_date"},$info{"author_tz"}), | 350 | "Date:" . format_date($info{"author_date"},$info{"author_tz"}), |
334 | $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj" : undef), | 351 | $url ? "URL: $url" : undef), |
335 | "", | 352 | "", |
336 | @{$info{"log"}}, | 353 | @{$info{"log"}}, |
337 | "", | 354 | "", |