From: Rudolf Polzer Date: Tue, 2 Mar 2010 10:30:30 +0000 (+0100) Subject: CGI support? X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=675f2d41effb6031f40088fedd6508d97370b84d;p=xonotic%2Fdiv0-gittools.git CGI support? --- diff --git a/git-branch-manager b/git-branch-manager index fe03402..43a8079 100755 --- a/git-branch-manager +++ b/git-branch-manager @@ -14,6 +14,16 @@ my %color = 'previous' => "\e[34m", ); +my %html_style = +( + '' => "color: white; background-color: black", + 'outstanding' => "color: white; background-color: yellow", + 'unmerge' => "color: white; background-color: red", + 'merge' => "color: white; background-color: green", + 'base' => "color: white; background-color: lightblue", + 'previous' => "color: white; background-color: blue", +); + my %name = ( 'outstanding' => "OUTSTANDING", @@ -47,9 +57,13 @@ sub run(@) } my $width = ($ENV{COLUMNS} || backtick 'tput', 'cols' || 80); -chomp(my $branch = backtick 'git', 'symbolic-ref', 'HEAD'); - $branch =~ s/^refs\/heads\/// - or die "Not in a branch"; +my $branch = $ENV{GIT_BRANCH}; +if(not $branch) +{ + chomp($branch = backtick 'git', 'symbolic-ref', 'HEAD'); + $branch =~ s/^refs\/heads\/// + or die "Not in a branch"; +} chomp(my $master = (backtick 'git', 'config', '--get', "branch-manager.$branch.master" or 'master')); chomp(my $datefilter = (backtick 'git', 'config', '--get', "branch-manager.$branch.startdate" or '')); my @datefilter = (); @@ -492,7 +506,19 @@ sub opt_rebase($$) }; } +sub escapeHTML { + my ($toencode,$newlinestoo) = @_; + return undef unless defined($toencode); + $toencode =~ s{&}{&}gso; + $toencode =~ s{<}{<}gso; + $toencode =~ s{>}{>}gso; + $toencode =~ s{"}{"}gso; + return $toencode; +} + + my $histsize = 20; +my $cgi_url = undef; sub opt_list($$) { ++$done; @@ -537,13 +563,27 @@ sub opt_list($$) my %seen = (); @l = reverse grep { !$seen{$_->[1]}++ && !$l->{bitmap}->[$l->{order_h}->{$_->[1]}] } reverse map { [$_->[1], $_->[2]] } sort { $l->{order_h}{$a->[2]} <=> $l->{order_h}{$b->[2]} or $a->[0] <=> $b->[0] } map { [$_, $l[$_]->[0], $l[$_]->[1]] } 0..(@l-1); } - for(@l) + if(defined $cgi_url) { - my ($action, $r) = @$_; - my $m = $l->{logmsg}->{$r}; - my $m_short = join ' ', map { s/^ (?!git-svn-id)(.)/$1/ ? $_ : () } split /\n/, $m; - $m_short = substr $m_short, 0, $width - 11 - 1 - 40 - 1; - printf "%s%-11s%s %s %s\n", $color{$action}, $name{$action}, $color{''}, $r, $m_short; + print "Content-Type: text/html\n\n\n"; + for(@l) + { + my ($action, $r) = @$_; + my $m = $l->{logmsg}->{$r}; + printf "\n", $html_style{$action}, $name{$action}, escapeHTML($r), escapeHTML($cgi_url), escapeHTML($r), escapeHTML($m); + } + print "
%s%s%s
\n"; + } + else + { + for(@l) + { + my ($action, $r) = @$_; + my $m = $l->{logmsg}->{$r}; + my $m_short = join ' ', map { s/^ (?!git-svn-id)(.)/$1/ ? $_ : () } split /\n/, $m; + $m_short = substr $m_short, 0, $width - 11 - 1 - 40 - 1; + printf "%s%-11s%s %s %s\n", $color{$action}, $name{$action}, $color{''}, $r, $m_short; + } } } @@ -596,7 +636,8 @@ my $result = GetOptions( "reset|R=s", handler sub { run_script ['reset', $_[1]]; }, "hardreset|H=s", handler sub { run_script ['hardreset', $_[1]]; }, "help|h", handler \&opt_help, - "histsize|s=i", \$histsize + "histsize|s=i", \$histsize, + "cgi|c=s", \$cgi_url ); if(!$done) {