[Nagiosplug-checkins] SF.net SVN: nagiosplug:[2266] nagiosplug/trunk/tools/git-notify

dermoth at users.sourceforge.net dermoth at users.sourceforge.net
Sat Oct 24 23:00:35 CEST 2009


Revision: 2266
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2266&view=rev
Author:   dermoth
Date:     2009-10-24 21:00:35 +0000 (Sat, 24 Oct 2009)

Log Message:
-----------
git-notify: Send notifications on ref changes, too

Do not only generate notifications on commits, but also if a branch head
or lightweight tag was created, removed, or modified.  Notifications on
branch head updates are omitted if one or more commit notification have
been generated and the branch head now references a descendant of the
originally referenced commit (which should be the usual case).

From: Holger Weiss <holger at zedat.fu-berlin.de>

Modified Paths:
--------------
    nagiosplug/trunk/tools/git-notify

Modified: nagiosplug/trunk/tools/git-notify
===================================================================
--- nagiosplug/trunk/tools/git-notify	2009-10-24 21:00:15 UTC (rev 2265)
+++ nagiosplug/trunk/tools/git-notify	2009-10-24 21:00:35 UTC (rev 2266)
@@ -47,6 +47,9 @@
 # debug mode
 my $debug = 0;
 
+# number of generated (non-CIA) notifications
+my $sent_notices = 0;
+
 # configuration parameters
 
 # base URL of the gitweb repository browser (can be set with the -u option)
@@ -272,6 +275,28 @@
     return %info;
 }
 
+# send a ref change notice to a mailing list
+sub send_ref_notice($$@)
+{
+    my ($ref, $action, @notice) = @_;
+    my ($reftype, $refname) = ($ref =~ /^refs\/(head|tag)s\/(.+)/);
+
+    $reftype =~ s/^head$/branch/;
+
+    @notice = (format_table(
+        "Module: $repos_name",
+        ($reftype eq "tag" ? "Tag:" : "Branch:") . $refname,
+        @notice,
+        ($action ne "removed" and $gitweb_url)
+            ? "URL: $gitweb_url/?a=shortlog;h=$ref" : undef),
+        "",
+        "The $refname $reftype has been $action.");
+
+    mail_notification($commitlist_address, "$refname $reftype $action",
+        "text/plain; charset=us-ascii", @notice);
+    $sent_notices++;
+}
+
 # send a commit notice to a mailing list
 sub send_commit_notice($$)
 {
@@ -315,6 +340,7 @@
     mail_notification($commitlist_address,
         $info{"author_name"} . ": " . ${$info{"log"}}[0],
         "text/plain; charset=UTF-8", @notice);
+    $sent_notices++;
 }
 
 # send a commit notice to the CIA server
@@ -383,44 +409,64 @@
     }
 
     mail_notification($commitlist_address, "New commits on branch $ref", "text/plain; charset=UTF-8", @$notice);
+    $sent_notices++;
 }
 
 # send all the notices
 sub send_all_notices($$$)
 {
     my ($old_sha1, $new_sha1, $ref) = @_;
+    my ($reftype, $refname, $action, @notice);
 
-    $ref =~ s/^refs\/heads\///;
+    return if ($ref =~ /^refs\/remotes\//
+        or (@include_list && !grep {$_ eq $ref} @include_list));
+    die "The name \"$ref\" doesn't sound like a local branch or tag"
+        if not (($reftype, $refname) = ($ref =~ /^refs\/(head|tag)s\/(.+)/));
 
-    return if (@include_list && !grep {$_ eq $ref} @include_list);
-
-    if ($old_sha1 eq '0' x 40)  # new ref
+    if ($new_sha1 eq '0' x 40)
     {
-        send_commit_notice( $ref, $new_sha1 ) if $commitlist_address;
-        return;
+        $action = "removed";
+        @notice = ( "Old SHA1: $old_sha1" );
     }
-
-    my @commits = ();
-
-    open LIST, "-|" or exec "git", "rev-list", @revlist_options, "^$old_sha1", "$new_sha1", @exclude_list or die "cannot exec git-rev-list";
-    while (<LIST>)
+    elsif ($old_sha1 eq '0' x 40)
     {
-        chomp;
-        die "invalid commit $_" unless /^[0-9a-f]{40}$/;
-        unshift @commits, $_;
+        $action = "created";
+        @notice = ( "SHA1: $new_sha1" );
     }
-    close LIST;
-
-    if (@commits > $max_individual_notices)
+    elsif ($reftype eq "tag")
     {
-        send_global_notice( $ref, $old_sha1, $new_sha1 ) if $commitlist_address;
-        return;
+        $action = "updated";
+        @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" );
     }
+    elsif (not grep( $_ eq $old_sha1, @{ git_rev_list( $new_sha1, "--full-history" ) } ))
+    {
+        $action = "rewritten";
+        @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" );
+    }
 
-    foreach my $commit (@commits)
+    send_ref_notice( $ref, $action, @notice ) if ($commitlist_address and $action);
+
+    unless ($reftype eq "tag" or $new_sha1 eq '0' x 40)
     {
-        send_commit_notice( $ref, $commit ) if $commitlist_address;
-        send_cia_notice( $ref, $commit ) if $cia_project_name;
+        my $commits = get_new_commits ( $old_sha1, $new_sha1 );
+
+        if (@$commits > $max_individual_notices)
+        {
+            send_global_notice( $refname, $old_sha1, $new_sha1 ) if $commitlist_address;
+        }
+        else
+        {
+            foreach my $commit (@$commits)
+            {
+                send_commit_notice( $refname, $commit ) if $commitlist_address;
+                send_cia_notice( $refname, $commit ) if $cia_project_name;
+            }
+        }
+        if ($sent_notices == 0 and $commitlist_address)
+        {
+            @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" );
+            send_ref_notice( $ref, "modified", @notice );
+        }
     }
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list