summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2009-11-07 01:23:32 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2009-11-07 01:23:32 (GMT)
commit40ef91694655a3abb425d994a1b862f956ac081c (patch)
tree4ca56bcfea4b38378afbfaaf1238dade34ba5f33 /tools
parent0775c9fc10e1128334763f516342d6b312508ef5 (diff)
downloadmonitoring-plugins-40ef91694655a3abb425d994a1b862f956ac081c.tar.gz
git-notify: Make abbreviating Gitweb URLs optional
The SHA1 object name part of Gitweb URLs is now only shortened if the user requested this by specifying the new "-z" option (or by setting "notify.shortURLs"). While at it, also shorten the additional URL which references a diff in e-mail notifications which don't include that diff inline because its size exceeds the maximum number of bytes specified via "-s". Note that while the abbreviated SHA1 object names will be unique at push time, this cannot be guaranteed for the future, so the shortened URLs might break some day.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/git-notify26
1 files changed, 17 insertions, 9 deletions
diff --git a/tools/git-notify b/tools/git-notify
index 0031fcd..289a5f6 100755
--- a/tools/git-notify
+++ b/tools/git-notify
@@ -27,6 +27,7 @@
27# -i branch If at least one -i is given, report only for specified branches 27# -i branch If at least one -i is given, report only for specified branches
28# -x branch Exclude changes to the specified branch from reports 28# -x branch Exclude changes to the specified branch from reports
29# -X Exclude merge commits 29# -X Exclude merge commits
30# -z Try to abbreviate the SHA1 name within gitweb URLs (unsafe)
30# 31#
31 32
32use strict; 33use strict;
@@ -56,6 +57,9 @@ my $show_committer = git_config( "notify.showcommitter" );
56# base URL of the gitweb repository browser (can be set with the -u option) 57# base URL of the gitweb repository browser (can be set with the -u option)
57my $gitweb_url = git_config( "notify.baseurl" ); 58my $gitweb_url = git_config( "notify.baseurl" );
58 59
60# abbreviate the SHA1 name within gitweb URLs (can be set with the -z option)
61my $abbreviate_url = git_config( "notify.shorturls" );
62
59# default repository name (can be changed with the -r option) 63# default repository name (can be changed with the -r option)
60my $repos_name = git_config( "notify.repository" ) || get_repos_name(); 64my $repos_name = git_config( "notify.repository" ) || get_repos_name();
61 65
@@ -101,6 +105,7 @@ sub usage()
101 print " -i branch If at least one -i is given, report only for specified branches\n"; 105 print " -i branch If at least one -i is given, report only for specified branches\n";
102 print " -x branch Exclude changes to the specified branch from reports\n"; 106 print " -x branch Exclude changes to the specified branch from reports\n";
103 print " -X Exclude merge commits\n"; 107 print " -X Exclude merge commits\n";
108 print " -z Try to abbreviate the SHA1 name within gitweb URLs (unsafe)\n";
104 exit 1; 109 exit 1;
105} 110}
106 111
@@ -282,6 +287,7 @@ sub parse_options()
282 elsif ($arg eq '-i') { push @include_list, shift @ARGV; } 287 elsif ($arg eq '-i') { push @include_list, shift @ARGV; }
283 elsif ($arg eq '-x') { push @exclude_list, shift @ARGV; } 288 elsif ($arg eq '-x') { push @exclude_list, shift @ARGV; }
284 elsif ($arg eq '-X') { push @revlist_options, "--no-merges"; } 289 elsif ($arg eq '-X') { push @revlist_options, "--no-merges"; }
290 elsif ($arg eq '-z') { $abbreviate_url = 1; }
285 elsif ($arg eq '-d') { $debug++; } 291 elsif ($arg eq '-d') { $debug++; }
286 else { usage(); } 292 else { usage(); }
287 } 293 }
@@ -404,17 +410,19 @@ sub send_commit_notice($$)
404 my ($ref,$obj) = @_; 410 my ($ref,$obj) = @_;
405 my %info = get_object_info($obj); 411 my %info = get_object_info($obj);
406 my @notice = (); 412 my @notice = ();
407 my ($url,$subject); 413 my ($url,$subject,$obj_string);
408 414
409 if ($gitweb_url) 415 if ($gitweb_url)
410 { 416 {
411 open REVPARSE, "-|" or exec "git", "rev-parse", "--short", $obj or die "cannot exec git-rev-parse"; 417 if ($abbreviate_url)
412 my $short_obj = <REVPARSE>; 418 {
413 close REVPARSE or die $! ? "Cannot execute rev-parse: $!" : "rev-parse exited with status: $?"; 419 open REVPARSE, "-|" or exec "git", "rev-parse", "--short", $obj or die "cannot exec git-rev-parse";
414 420 $obj_string = <REVPARSE>;
415 $short_obj = $obj if not defined $short_obj; 421 chomp $obj_string if defined $obj_string;
416 chomp $short_obj; 422 close REVPARSE or die $! ? "Cannot execute rev-parse: $!" : "rev-parse exited with status: $?";
417 $url = "$gitweb_url/?a=$info{type};h=$short_obj"; 423 }
424 $obj_string = $obj if not defined $obj_string;
425 $url = "$gitweb_url/?a=$info{type};h=$obj_string";
418 } 426 }
419 427
420 if ($info{"type"} eq "tag") 428 if ($info{"type"} eq "tag")
@@ -461,7 +469,7 @@ sub send_commit_notice($$)
461 } 469 }
462 else 470 else
463 { 471 {
464 push @notice, "Diff: $gitweb_url/?a=commitdiff;h=$obj" if $gitweb_url; 472 push @notice, "Diff: $gitweb_url/?a=commitdiff;h=$obj_string" if $gitweb_url;
465 } 473 }
466 $subject = $info{"author_name"}; 474 $subject = $info{"author_name"};
467 } 475 }