diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 22:55:44 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 22:55:44 +0200 |
commit | 85512d7f111e9b05446a012567f76472f5d5410c (patch) | |
tree | 4b3f47af8105c1f9f49b16ee079d44da2228d8c1 | |
parent | af5e252846d08a579835e9b3bd0b004727252850 (diff) | |
download | monitoring-plugins-85512d7f111e9b05446a012567f76472f5d5410c.tar.gz |
git-notify: Handle non-UTF-8 commits
Make sure that commit messages which use an encoding other than US-ASCII
or UTF-8 are handled correctly. Also, assume that the diff contents use
the same encoding as the commit message. This assumption may well be
wrong, but that's the best we can do.
-rwxr-xr-x | tools/git-notify | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/git-notify b/tools/git-notify index a89104a6..b10b1bc4 100755 --- a/tools/git-notify +++ b/tools/git-notify | |||
@@ -28,14 +28,10 @@ | |||
28 | # | 28 | # |
29 | 29 | ||
30 | use strict; | 30 | use strict; |
31 | use open ':utf8'; | ||
32 | use Fcntl ':flock'; | 31 | use Fcntl ':flock'; |
33 | use Encode 'encode'; | 32 | use Encode qw(encode decode); |
34 | use Cwd 'realpath'; | 33 | use Cwd 'realpath'; |
35 | 34 | ||
36 | binmode STDIN, ':utf8'; | ||
37 | binmode STDOUT, ':utf8'; | ||
38 | |||
39 | sub git_config($); | 35 | sub git_config($); |
40 | sub get_repos_name(); | 36 | sub get_repos_name(); |
41 | 37 | ||
@@ -296,6 +292,7 @@ sub mail_notification($$$@) | |||
296 | $subject = encode("MIME-Q",$subject); | 292 | $subject = encode("MIME-Q",$subject); |
297 | if ($debug) | 293 | if ($debug) |
298 | { | 294 | { |
295 | binmode STDOUT, ":utf8"; | ||
299 | print "---------------------\n"; | 296 | print "---------------------\n"; |
300 | print "To: $name\n"; | 297 | print "To: $name\n"; |
301 | print "Subject: $subject\n"; | 298 | print "Subject: $subject\n"; |
@@ -310,6 +307,7 @@ sub mail_notification($$$@) | |||
310 | { | 307 | { |
311 | exec $mailer, "-s", $subject, "-a", "Content-Type: $content_type", $name or die "Cannot exec $mailer"; | 308 | exec $mailer, "-s", $subject, "-a", "Content-Type: $content_type", $name or die "Cannot exec $mailer"; |
312 | } | 309 | } |
310 | binmode MAIL, ":utf8"; | ||
313 | print MAIL join("\n", @text), "\n"; | 311 | print MAIL join("\n", @text), "\n"; |
314 | close MAIL; | 312 | close MAIL; |
315 | } | 313 | } |
@@ -334,12 +332,15 @@ sub get_object_info($) | |||
334 | my @log = (); | 332 | my @log = (); |
335 | my $do_log = 0; | 333 | my $do_log = 0; |
336 | 334 | ||
335 | $info{"encoding"} = "utf-8"; | ||
336 | |||
337 | open OBJ, "-|" or exec "git", "cat-file", "commit", $obj or die "cannot run git-cat-file"; | 337 | open OBJ, "-|" or exec "git", "cat-file", "commit", $obj or die "cannot run git-cat-file"; |
338 | while (<OBJ>) | 338 | while (<OBJ>) |
339 | { | 339 | { |
340 | chomp; | 340 | chomp; |
341 | if ($do_log) { push @log, $_; } | 341 | if ($do_log) { push @log, $_; } |
342 | elsif (/^$/) { $do_log = 1; } | 342 | elsif (/^$/) { $do_log = 1; } |
343 | elsif (/^encoding (.+)/) { $info{"encoding"} = $1; } | ||
343 | elsif (/^(author|committer) ((.*) (<.*>)) (\d+) ([+-]\d+)$/) | 344 | elsif (/^(author|committer) ((.*) (<.*>)) (\d+) ([+-]\d+)$/) |
344 | { | 345 | { |
345 | $info{$1} = $2; | 346 | $info{$1} = $2; |
@@ -429,6 +430,8 @@ sub send_commit_notice($$) | |||
429 | push @notice, "Diff: $gitweb_url/?a=commitdiff;h=$obj" if $gitweb_url; | 430 | push @notice, "Diff: $gitweb_url/?a=commitdiff;h=$obj" if $gitweb_url; |
430 | } | 431 | } |
431 | 432 | ||
433 | $_ = decode($info{"encoding"}, $_) for @notice; | ||
434 | |||
432 | mail_notification($commitlist_address, | 435 | mail_notification($commitlist_address, |
433 | $info{"author_name"} . ": " . truncate_str(${$info{"log"}}[0], 50), | 436 | $info{"author_name"} . ": " . truncate_str(${$info{"log"}}[0], 50), |
434 | "text/plain; charset=UTF-8", @notice); | 437 | "text/plain; charset=UTF-8", @notice); |