Revision: 2263
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2263&view=rev
Author: dermoth
Date: 2009-10-24 20:59:52 +0000 (Sat, 24 Oct 2009)
Log Message:
-----------
git-notify: New subroutine for column alignment
Most notifications include an ASCII "table" with two columns. The
formatting of these columns is now handled by the new format_table()
subroutine, so that the alignment can easily be changed in the future.
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 20:59:46 UTC (rev 2262)
+++ nagiosplug/trunk/tools/git-notify 2009-10-24 20:59:52 UTC (rev 2263)
@@ -102,6 +102,33 @@
return $str;
}
+# right-justify the left column of "left: right" elements, omit undefined elements
+sub format_table(@)
+{
+ my @lines = @_;
+ my @table;
+ my $max = 0;
+
+ foreach my $line (@lines)
+ {
+ next if not defined $line;
+ my $pos = index($line, ":");
+
+ $max = $pos if $pos > $max;
+ }
+
+ foreach my $line (@lines)
+ {
+ next if not defined $line;
+ my ($left, $right) = split(/: */, $line, 2);
+
+ push @table, (defined $left and defined $right)
+ ? sprintf("%*s: %s", $max + 1, $left, $right)
+ : $line;
+ }
+ return @table;
+}
+
# format an integer date + timezone as string
# algorithm taken from git's date.c
sub format_date($$)
@@ -236,15 +263,15 @@
return if length($diff) == 0;
- push @notice,
+ push @notice, format_table(
"Module: $repos_name",
"Branch: $ref",
"Commit: $obj",
- $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj\n" : "",
- "Author: " . $info{"author"},
- "Date: " . format_date($info{"author_date"},$info{"author_tz"}),
+ $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj" : undef),
+ "Author:" . $info{"author"},
+ "Date:" . format_date($info{"author_date"},$info{"author_tz"}),
"",
- join "\n", @{$info{"log"}},
+ @{$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.