summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: db63fbf)
raw | patch | inline | side by side (parent: db63fbf)
author | Holger Weiss <holger@zedat.fu-berlin.de> | |
Sat, 24 Oct 2009 09:44:21 +0000 (11:44 +0200) | ||
committer | Holger Weiss <holger@zedat.fu-berlin.de> | |
Sat, 24 Oct 2009 09:44:21 +0000 (11:44 +0200) |
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.
formatting of these columns is now handled by the new format_table()
subroutine, so that the alignment can easily be changed in the future.
tools/git-notify | patch | blob | history |
diff --git a/tools/git-notify b/tools/git-notify
index ccde4bee6e186bf06992b3308d6caf6905e9bd21..0c2f7395fd2c1484aff70b739c0c3d884ea8d2c7 100755 (executable)
--- a/tools/git-notify
+++ b/tools/git-notify
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($$)
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"}},
"",
"---",
"";