\n";
}
$alternate ^= 1;
- if ($op eq "+") {
+ if ($status eq "N") {
my $mode_chng = "";
- if (S_ISREG(oct $mode)) {
- $mode_chng = sprintf(" with mode: %04o", (oct $mode) & 0777);
+ if (S_ISREG(oct $to_mode)) {
+ $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
}
print "" .
- $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hp=$hash;f=$file", -class => "list"}, escapeHTML($file)) . " | \n" .
- "[new " . file_type($mode) . "$mode_chng] | \n" .
- "" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . " | \n";
- } elsif ($op eq "-") {
+ $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hp=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "\n" .
+ "[new " . file_type($to_mode) . "$mode_chng] | \n" .
+ "" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . " | \n";
+ } elsif ($status eq "D") {
print "" .
- $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . " | \n" .
- "[deleted " . file_type($mode). "] | \n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "\n" .
+ "[deleted " . file_type($from_mode). "] | \n" .
"" .
- $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") .
+ $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") .
" | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") .
" | \n"
- } elsif ($op eq "*") {
- $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
- my $from_id = $1;
- my $to_id = $2;
- $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
- my $from_mode = $1;
- my $to_mode = $2;
+ } elsif ($status eq "M" || $status eq "T") {
my $mode_chnge = "";
if ($from_mode != $to_mode) {
$mode_chnge = " [changed";
@@ -1342,18 +1485,18 @@ sub git_commit {
}
sub git_blobdiff {
- mkdir($gittmp, 0700);
+ mkdir($git_temp, 0700);
git_header_html();
if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
print "\n" .
- $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
" | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
" | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
- " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree");
- if (defined $file_name) {
- print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
- }
- print "
\n" .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") .
+ "
\n";
+ print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent"}, "plain") .
"
\n";
print "\n" .
$cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
@@ -1364,9 +1507,7 @@ sub git_blobdiff {
"
$hash vs $hash_parent
\n";
}
if (defined $file_name) {
- print "
\n" .
- "/$file_name\n" .
- "
\n";
+ print "
/$file_name
\n";
}
print "
\n" .
"
blob:" .
@@ -1374,13 +1515,19 @@ sub git_blobdiff {
" -> blob:" .
$cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
"
\n";
- git_diff_html($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
+ git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
print "
";
git_footer_html();
}
+sub git_blobdiff_plain {
+ mkdir($git_temp, 0700);
+ print $cgi->header(-type => "text/plain", -charset => 'utf-8');
+ git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
+}
+
sub git_commitdiff {
- mkdir($gittmp, 0700);
+ mkdir($git_temp, 0700);
my %co = git_read_commit($hash);
if (!%co) {
die_error(undef, "Unknown commit object.");
@@ -1388,17 +1535,20 @@ sub git_commitdiff {
if (!defined $hash_parent) {
$hash_parent = $co{'parent'};
}
- open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" || die_error(undef, "Open failed.");
+ open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
my (@difftree) = map { chomp; $_ } <$fd>;
- close $fd || die_error(undef, "Reading diff-tree failed.");
+ close $fd or die_error(undef, "Reading diff-tree failed.");
git_header_html();
print "
\n" .
- $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
" | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
- " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
- " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") .
- "
\n";
+ " | commitdiff" .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "
\n";
+ print $cgi->a({-href => "$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent"}, "plain") . "\n" .
+ "
\n";
print "\n" .
$cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
"
\n";
@@ -1428,39 +1578,33 @@ sub git_commitdiff {
}
print "
\n";
foreach my $line (@difftree) {
- # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
- $line =~ m/^(.)(.+)\t(.+)\t([0-9a-fA-F]{40}|[0-9a-fA-F]{40}->[0-9a-fA-F]{40})\t(.+)$/;
- my $op = $1;
- my $mode = $2;
- my $type = $3;
- my $id = $4;
- my $file = $5;
- if ($type eq "blob") {
- if ($op eq "+") {
- print "" . file_type($mode) . ":" .
- $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, $id) . "(new)" .
- "
\n";
- git_diff_html(undef, "/dev/null", $id, "b/$file");
- } elsif ($op eq "-") {
- print "" . file_type($mode) . ":" .
- $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, $id) . "(deleted)" .
- "
\n";
- git_diff_html($id, "a/$file", undef, "/dev/null");
- } elsif ($op eq "*") {
- $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
- my $from_id = $1;
- my $to_id = $2;
- $mode =~ m/([0-7]+)->([0-7]+)/;
- my $from_mode = $1;
- my $to_mode = $2;
- if ($from_id ne $to_id) {
- print "" .
- file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
- " -> " .
- file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
- print "
\n";
- git_diff_html($from_id, "a/$file", $to_id, "b/$file");
- }
+ # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
+ # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
+ $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
+ my $from_mode = $1;
+ my $to_mode = $2;
+ my $from_id = $3;
+ my $to_id = $4;
+ my $status = $5;
+ my $file = $6;
+ if ($status eq "N") {
+ print "" . file_type($to_mode) . ":" .
+ $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
+ "
\n";
+ git_diff_print(undef, "/dev/null", $to_id, "b/$file");
+ } elsif ($status eq "D") {
+ print "" . file_type($from_mode) . ":" .
+ $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) . "(deleted)" .
+ "
\n";
+ git_diff_print($from_id, "a/$file", undef, "/dev/null");
+ } elsif ($status eq "M") {
+ if ($from_id ne $to_id) {
+ print "" .
+ file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
+ " -> " .
+ file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
+ print "
\n";
+ git_diff_print($from_id, "a/$file", $to_id, "b/$file");
}
}
}
@@ -1469,6 +1613,29 @@ sub git_commitdiff {
git_footer_html();
}
+sub git_commitdiff_plain {
+ mkdir($git_temp, 0700);
+ open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
+ my (@difftree) = map { chomp; $_ } <$fd>;
+ close $fd or die_error(undef, "Reading diff-tree failed.");
+
+ print $cgi->header(-type => "text/plain", -charset => 'utf-8');
+ foreach my $line (@difftree) {
+ $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
+ my $from_id = $3;
+ my $to_id = $4;
+ my $status = $5;
+ my $file = $6;
+ if ($status eq "N") {
+ git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
+ } elsif ($status eq "D") {
+ git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
+ } elsif ($status eq "M") {
+ git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
+ }
+ }
+}
+
sub git_history {
if (!defined $hash) {
$hash = git_read_hash("$project/HEAD");
@@ -1479,17 +1646,18 @@ sub git_history {
}
git_header_html();
print "\n" .
- $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
- $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") . " | " .
- $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
"
\n" .
"
\n";
print "\n" .
$cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
"
\n";
- print "\n" .
- "/$file_name
\n";
- print "
\n";
+ print "/$file_name
\n";
open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
my $commit;
@@ -1500,7 +1668,7 @@ sub git_history {
$commit = $1;
next;
}
- if ($line =~ m/^(.)(.+)\t(.+)\t([0-9a-fA-F]{40}->[0-9a-fA-F]{40})\t(.+)$/ && (defined $commit)) {
+ if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
my %co = git_read_commit($commit);
if (!%co) {
next;
@@ -1512,16 +1680,16 @@ sub git_history {
}
$alternate ^= 1;
print "$co{'age_string'} | \n" .
- "" . escapeHTML(chop_str($co{'author_name'}, 10)) . " | \n" .
- "" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "" . escapeHTML($co{'title'}) . "") . " | \n" .
+ "" . escapeHTML(chop_str($co{'author_name'}, 15, 3)) . " | \n" .
+ "" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "" .
+ escapeHTML(chop_str($co{'title'}, 50)) . "") . " | \n" .
"" .
$cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
- " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$commit"}, "tree") .
" | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file_name"}, "blob");
my $blob = git_get_hash_by_path($hash, $file_name);
my $blob_parent = git_get_hash_by_path($commit, $file_name);
if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
- print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"}, "diff");
+ print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"}, "diff to current");
}
print " | \n" .
"
\n";
@@ -1532,3 +1700,192 @@ sub git_history {
close $fd;
git_footer_html();
}
+
+sub git_search {
+ if (!defined $searchtext) {
+ die_error("", "Text field empty.");
+ }
+ if (!defined $hash) {
+ $hash = git_read_hash("$project/HEAD");
+ }
+ my %co = git_read_commit($hash);
+ if (!%co) {
+ die_error(undef, "Unknown commit object.");
+ }
+ git_header_html();
+ print "\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
+ "
\n" .
+ "
\n";
+
+ print "\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
+ "
\n";
+ print "\n";
+ $/ = "\0";
+ open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
+ my $alternate = 0;
+ while (my $commit_text = <$fd>) {
+ if (!grep m/$searchtext/, $commit_text) {
+ next;
+ }
+ my @commit_lines = split "\n", $commit_text;
+ my $commit = shift @commit_lines;
+ my %co = git_read_commit($commit, \@commit_lines);
+ if (!%co) {
+ next;
+ }
+ if ($alternate) {
+ print "\n";
+ } else {
+ print "
\n";
+ }
+ $alternate ^= 1;
+ print "$co{'age_string'} | \n" .
+ "" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . " | \n" .
+ "" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "" . escapeHTML(chop_str($co{'title'}, 50)) . " ");
+ my $comment = $co{'comment'};
+ foreach my $line (@$comment) {
+ if ($line =~ m/^(.*)($searchtext)(.*)$/) {
+ my $lead = escapeHTML($1) || "";
+ $lead = chop_str($lead, 30, 10);
+ my $match = escapeHTML($2) || "";
+ my $trail = escapeHTML($3) || "";
+ $trail = chop_str($trail, 30, 10);
+ my $text = "$lead$match$trail";
+ print chop_str($text, 80, 5) . " \n";
+ }
+ }
+ print " | \n" .
+ "" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
+ print " | \n" .
+ "
\n";
+ }
+ close $fd;
+
+ $/ = "\n";
+ open $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
+ undef %co;
+ my @files;
+ while (my $line = <$fd>) {
+ if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
+ my %set;
+ $set{'file'} = $6;
+ $set{'from_id'} = $3;
+ $set{'to_id'} = $4;
+ $set{'id'} = $set{'to_id'};
+ if ($set{'id'} =~ m/0{40}/) {
+ $set{'id'} = $set{'from_id'};
+ }
+ if ($set{'id'} =~ m/0{40}/) {
+ next;
+ }
+ push @files, \%set;
+ } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
+ if (%co) {
+ if ($alternate) {
+ print "\n";
+ } else {
+ print "
\n";
+ }
+ $alternate ^= 1;
+ print "$co{'age_string'} | \n" .
+ "" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . " | \n" .
+ "" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "" .
+ escapeHTML(chop_str($co{'title'}, 50)) . " ");
+ while (my $setref = shift @files) {
+ my %set = %$setref;
+ print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
+ escapeHTML($set{'file'})) . " \n";
+ }
+ print " | \n" .
+ "" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
+ print " | \n" .
+ "
\n";
+ }
+ %co = git_read_commit($1);
+ }
+ }
+ print "
\n";
+ close $fd;
+ git_footer_html();
+}
+
+sub git_shortlog {
+ my $head = git_read_hash("$project/HEAD");
+ if (!defined $hash) {
+ $hash = $head;
+ }
+
+ git_header_html();
+ print "\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
+ " | shortlog" .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "
\n";
+ if ($hash ne $head) {
+ print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD") . " ⋅ ";
+ }
+ print $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "100") .
+ " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;t=1;h=$hash"}, "day") .
+ " ⋅ " .$cgi->a({-href => "$my_uri?p=$project;a=shortlog;t=7;h=$hash"}, "week") .
+ " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;t=31;h=$hash"}, "month") .
+ " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;t=365;h=$hash"}, "year") .
+ " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;t=0;h=$hash"}, "all") .
+ "
\n" .
+ "
\n";
+ my $limit = "";
+ if (defined $time_back) {
+ if ($time_back) {
+ $limit = sprintf(" --max-age=%i", time - 60*60*24*$time_back);
+ }
+ } else {
+ $limit = " --max-count=100";
+ }
+ open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
+ my (@revlist) = map { chomp; $_ } <$fd>;
+ close $fd;
+ print "\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
+ "
\n";
+ print "