From 765c08d15b819c8b9d41caeaa8fa23b4729efd44 Mon Sep 17 00:00:00 2001
From: Holger Weiss <holger@zedat.fu-berlin.de>
Date: Sat, 7 Nov 2009 02:11:52 +0100
Subject: Revert "git-notify: Remove unused [...] code"

This reverts commit 5445b9769f254781e482062bacc6603a5cd63059.  Alexandre
Julliard pointed out that the code in question was used if git-notify
was explicitly called with the SHA1 name of an annotated tag object.  At
the moment, the code in question actually _is_ unused due to later
modifications, but it wasn't at the time 5445b976 was committed, and
we'll add further changes so that the code will be used again in the
future.

Conflicts:

	tools/git-notify

diff --git a/tools/git-notify b/tools/git-notify
index ebede1a..f524fd7 100755
--- a/tools/git-notify
+++ b/tools/git-notify
@@ -325,7 +325,7 @@ sub get_repos_name()
     return $repos;
 }
 
-# extract the information from a commit object and return a hash containing the various fields
+# extract the information from a commit or tag object and return a hash containing the various fields
 sub get_object_info($)
 {
     my $obj = shift;
@@ -335,14 +335,21 @@ sub get_object_info($)
 
     $info{"encoding"} = "utf-8";
 
-    open OBJ, "-|" or exec "git", "cat-file", "commit", $obj or die "cannot run git-cat-file";
+    open TYPE, "-|" or exec "git", "cat-file", "-t", $obj or die "cannot run git-cat-file";
+    my $type = <TYPE>;
+    chomp $type;
+    close TYPE or die $! ? "Cannot execute cat-file: $!" : "cat-file exited with status: $?";
+
+    open OBJ, "-|" or exec "git", "cat-file", $type, $obj or die "cannot run git-cat-file";
     while (<OBJ>)
     {
         chomp;
-        if ($do_log) { push @log, $_; }
-        elsif (/^$/) { $do_log = 1; }
-        elsif (/^encoding (.+)/) { $info{"encoding"} = $1; }
-        elsif (/^(author|committer) ((.*) (<.*>)) (\d+) ([+-]\d+)$/)
+        if ($do_log)
+        {
+            last if /^-----BEGIN PGP SIGNATURE-----/;
+            push @log, $_;
+        }
+        elsif (/^(author|committer|tagger) ((.*) (<.*>)) (\d+) ([+-]\d+)$/)
         {
             $info{$1} = $2;
             $info{$1 . "_name"} = $3;
@@ -350,9 +357,19 @@ sub get_object_info($)
             $info{$1 . "_date"} = $5;
             $info{$1 . "_tz"} = $6;
         }
+        elsif (/^tag (.+)/)
+        {
+            $info{"tag"} = $1;
+        }
+        elsif (/^encoding (.+)/)
+        {
+            $info{"encoding"} = $1;
+        }
+        elsif (/^$/) { $do_log = 1; }
     }
     close OBJ or die $! ? "Cannot execute cat-file: $!" : "cat-file exited with status: $?";
 
+    $info{"type"} = $type;
     $info{"log"} = \@log;
     return %info;
 }
@@ -385,7 +402,7 @@ sub send_commit_notice($$)
     my ($ref,$obj) = @_;
     my %info = get_object_info($obj);
     my @notice = ();
-    my $url;
+    my ($url,$subject);
 
     open DIFF, "-|" or exec "git", "diff-tree", "-p", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree";
     my $diff = join("", <DIFF>);
@@ -401,41 +418,57 @@ sub send_commit_notice($$)
 
         $short_obj = $obj if not defined $short_obj;
         chomp $short_obj;
-        $url = "$gitweb_url/?a=commit;h=$short_obj";
+        $url = "$gitweb_url/?a=$info{type};h=$short_obj";
     }
 
-    push @notice, format_table(
-        "Module: $repos_name",
-        "Branch: $ref",
-        "Commit: $obj",
-        "Author:" . $info{"author"},
-        $info{"committer"} ne $info{"author"} ? "Committer:" . $info{"committer"} : undef,
-        "Date:" . format_date($info{"author_date"},$info{"author_tz"}),
-        $url ? "URL: $url" : undef),
-        "",
-        @{$info{"log"}},
-        "",
-        "---",
-        "";
-
-    open STAT, "-|" or exec "git", "diff-tree", "--stat", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree";
-    push @notice, join("", <STAT>);
-    close STAT or die $! ? "Cannot execute diff-tree: $!" : "diff-tree exited with status: $?";
-
-    if (($max_diff_size == -1) || (length($diff) < $max_diff_size))
+    if ($info{"type"} eq "tag")
     {
-        push @notice, $diff;
+        push @notice, format_table(
+          "Module: $repos_name",
+          "Branch: $ref",
+          "Tag: $obj",
+          "Tagger:" . $info{"tagger"},
+          "Date:" . format_date($info{"tagger_date"},$info{"tagger_tz"}),
+          $url ? "URL: $url" : undef),
+          "",
+          join "\n", @{$info{"log"}};
+
+        $subject = "Tag " . $info{"tag"} . ": " . $info{"tagger_name"};
     }
     else
     {
-        push @notice, "Diff:   $gitweb_url/?a=commitdiff;h=$obj" if $gitweb_url;
+        push @notice, format_table(
+          "Module: $repos_name",
+          "Branch: $ref",
+          "Commit: $obj",
+          "Author:" . $info{"author"},
+          $info{"committer"} ne $info{"author"} ? "Committer:" . $info{"committer"} : undef,
+          "Date:" . format_date($info{"author_date"},$info{"author_tz"}),
+          $url ? "URL: $url" : undef),
+          "",
+          @{$info{"log"}},
+          "",
+          "---",
+          "";
+
+        open STAT, "-|" or exec "git", "diff-tree", "--stat", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree";
+        push @notice, join("", <STAT>);
+        close STAT or die $! ? "Cannot execute diff-tree: $!" : "diff-tree exited with status: $?";
+
+        if (($max_diff_size == -1) || (length($diff) < $max_diff_size))
+        {
+            push @notice, $diff;
+        }
+        else
+        {
+            push @notice, "Diff:   $gitweb_url/?a=commitdiff;h=$obj" if $gitweb_url;
+        }
+        $subject = $info{"author_name"};
     }
 
+    $subject .= ": " . truncate_str(${$info{"log"}}[0],50);
     $_ = decode($info{"encoding"}, $_) for @notice;
-
-    mail_notification($commitlist_address,
-        $info{"author_name"} . ": " . truncate_str(${$info{"log"}}[0], 50),
-        "text/plain; charset=UTF-8", @notice);
+    mail_notification($commitlist_address, $subject, "text/plain; charset=UTF-8", @notice);
     $sent_notices++;
 }
 
@@ -446,6 +479,8 @@ sub send_cia_notice($$)
     my %info = get_object_info($commit);
     my @cia_text = ();
 
+    return if $info{"type"} ne "commit";
+
     push @cia_text,
         "<message>",
         "  <generator>",
-- 
cgit v0.10-9-g596f

