SF.net SVN: nagiosplug:[2269] nagiosplug/trunk/tools/git-notify

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 2269
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2269&view=rev
Author:   dermoth
Date:     2009-10-24 21:01:06 +0000 (Sat, 24 Oct 2009)

Log Message:
-----------
git-nofity: Try to shorten Gitweb URLs

Instead of using the full SHA1 values of commit object names within
Gitweb URLs, try to abbreviate them to a shorter unique name.

From: Holger Weiss <[email protected]>

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

Modified: nagiosplug/trunk/tools/git-notify
===================================================================
--- nagiosplug/trunk/tools/git-notify	2009-10-24 21:00:55 UTC (rev 2268)
+++ nagiosplug/trunk/tools/git-notify	2009-10-24 21:01:06 UTC (rev 2269)
@@ -168,6 +168,11 @@
     return @table;
 }
 
+# return the gitweb URL of the given commit or undef
+sub gitweb_url($$)
+{
+}
+
 # format an integer date + timezone as string
 # algorithm taken from git's date.c
 sub format_date($$)
@@ -317,6 +322,7 @@
     my ($ref,$obj) = @_;
     my %info = get_object_info($obj);
     my @notice = ();
+    my $url;
 
     open DIFF, "-|" or exec "git", "diff-tree", "-p", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree";
     my $diff = join("", <DIFF>);
@@ -324,6 +330,17 @@
 
     return if length($diff) == 0;
 
+    if ($gitweb_url)
+    {
+        open REVPARSE, "-|" or exec "git", "rev-parse", "--short", $obj or die "cannot exec git-rev-parse";
+        my $short_obj = <REVPARSE>;
+        close REVPARSE or die $! ? "Cannot execute rev-parse: $!" : "rev-parse exited with status: $?";
+
+        $short_obj = $obj if not defined $short_obj;
+        chomp $short_obj;
+        $url = "$gitweb_url/?a=commit;h=$short_obj";
+    }
+
     push @notice, format_table(
         "Module: $repos_name",
         "Branch: $ref",
@@ -331,7 +348,7 @@
         "Author:" . $info{"author"},
         $info{"committer"} ne $info{"author"} ? "Committer:" . $info{"committer"} : undef,
         "Date:" . format_date($info{"author_date"},$info{"author_tz"}),
-        $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj" : undef),
+        $url ? "URL: $url" : undef),
         "",
         @{$info{"log"}},
         "",


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

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.