Explorar el Código

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.
Holger Weiss hace 16 años
padre
commit
85512d7f11
Se han modificado 1 ficheros con 8 adiciones y 5 borrados
  1. 8 5
      tools/git-notify

+ 8 - 5
tools/git-notify

@@ -28,14 +28,10 @@
 #
 #
 
 
 use strict;
 use strict;
-use open ':utf8';
 use Fcntl ':flock';
 use Fcntl ':flock';
-use Encode 'encode';
+use Encode qw(encode decode);
 use Cwd 'realpath';
 use Cwd 'realpath';
 
 
-binmode STDIN, ':utf8';
-binmode STDOUT, ':utf8';
-
 sub git_config($);
 sub git_config($);
 sub get_repos_name();
 sub get_repos_name();
 
 
@@ -296,6 +292,7 @@ sub mail_notification($$$@)
     $subject = encode("MIME-Q",$subject);
     $subject = encode("MIME-Q",$subject);
     if ($debug)
     if ($debug)
     {
     {
+        binmode STDOUT, ":utf8";
         print "---------------------\n";
         print "---------------------\n";
         print "To: $name\n";
         print "To: $name\n";
         print "Subject: $subject\n";
         print "Subject: $subject\n";
@@ -310,6 +307,7 @@ sub mail_notification($$$@)
         {
         {
             exec $mailer, "-s", $subject, "-a", "Content-Type: $content_type", $name or die "Cannot exec $mailer";
             exec $mailer, "-s", $subject, "-a", "Content-Type: $content_type", $name or die "Cannot exec $mailer";
         }
         }
+        binmode MAIL, ":utf8";
         print MAIL join("\n", @text), "\n";
         print MAIL join("\n", @text), "\n";
         close MAIL;
         close MAIL;
     }
     }
@@ -334,12 +332,15 @@ sub get_object_info($)
     my @log = ();
     my @log = ();
     my $do_log = 0;
     my $do_log = 0;
 
 
+    $info{"encoding"} = "utf-8";
+
     open OBJ, "-|" or exec "git", "cat-file", "commit", $obj or die "cannot run git-cat-file";
     open OBJ, "-|" or exec "git", "cat-file", "commit", $obj or die "cannot run git-cat-file";
     while (<OBJ>)
     while (<OBJ>)
     {
     {
         chomp;
         chomp;
         if ($do_log) { push @log, $_; }
         if ($do_log) { push @log, $_; }
         elsif (/^$/) { $do_log = 1; }
         elsif (/^$/) { $do_log = 1; }
+        elsif (/^encoding (.+)/) { $info{"encoding"} = $1; }
         elsif (/^(author|committer) ((.*) (<.*>)) (\d+) ([+-]\d+)$/)
         elsif (/^(author|committer) ((.*) (<.*>)) (\d+) ([+-]\d+)$/)
         {
         {
             $info{$1} = $2;
             $info{$1} = $2;
@@ -429,6 +430,8 @@ sub send_commit_notice($$)
         push @notice, "Diff:   $gitweb_url/?a=commitdiff;h=$obj" if $gitweb_url;
         push @notice, "Diff:   $gitweb_url/?a=commitdiff;h=$obj" if $gitweb_url;
     }
     }
 
 
+    $_ = decode($info{"encoding"}, $_) for @notice;
+
     mail_notification($commitlist_address,
     mail_notification($commitlist_address,
         $info{"author_name"} . ": " . truncate_str(${$info{"log"}}[0], 50),
         $info{"author_name"} . ": " . truncate_str(${$info{"log"}}[0], 50),
         "text/plain; charset=UTF-8", @notice);
         "text/plain; charset=UTF-8", @notice);