From: Eric Wong Date: Tue, 29 Dec 2015 09:20:01 +0000 (+0000) Subject: repobrowse: log display tweaks X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e1b49ab0d515523e3657e7bf81b6574ba73506e6;p=thirdparty%2Fpublic-inbox.git repobrowse: log display tweaks --graph is probably not supportable, but we'll make due with being able to have links to follow arbitrary parents. --skip and ref~ do not scale to large repositories, either. --- diff --git a/lib/PublicInbox/RepoBrowseGitLog.pm b/lib/PublicInbox/RepoBrowseGitLog.pm index 7dfa7d3fc..a4245d0ad 100644 --- a/lib/PublicInbox/RepoBrowseGitLog.pm +++ b/lib/PublicInbox/RepoBrowseGitLog.pm @@ -6,14 +6,10 @@ use strict; use warnings; use PublicInbox::Hval qw(utf8_html); use base qw(PublicInbox::RepoBrowseBase); -use PublicInbox::RepoBrowseGit qw(git_dec_links); - -# enable if we can speed it up..., over 100ms is unnacceptable -my @graph; # = qw(--graph); - +use PublicInbox::RepoBrowseGit qw(git_dec_links git_commit_title); # cannot rely on --date=format-local:... yet, it is too new (September 2015) my $LOG_FMT = '--pretty=tformat:'. - join('%x00', (@graph ? '' : '%n'), qw(%h s%s D%D)); + join('%x00', qw(%h %p %s D%D)); my $MSG_FMT = join('%x00', '', qw(%ai a%an b%b)); sub call_git_log { @@ -33,52 +29,49 @@ sub call_git_log { my $git = $repo_info->{git}; my $log = $git->popen(qw(log --no-notes --no-color - --abbrev-commit --abbrev=10), - @graph, $fmt, "-$max", $h); + --abbrev-commit --abbrev=12), + $fmt, "-$max", $h); sub { my ($res) = @_; # Plack callback my $fh = $res->([200, ['Content-Type'=>'text/html']]); - git_log_stream($req, $q, $log, $fh); + git_log_stream($req, $q, $log, $fh, $git); $fh->close; } } sub git_log_stream { - my ($req, $q, $log, $fh) = @_; + my ($req, $q, $log, $fh, $git) = @_; my $desc = $req->{repo_info}->{desc_html}; - my ($x, $author); my $showmsg = $q->{showmsg}; + my $x = 'commit log '; if ($showmsg) { + $showmsg = "&showmsg=1"; my $qs = $q->qs(showmsg => ''); $qs = $req->{cgi}->path_info if ($qs eq ''); - $x = qq{collapse}; + $x .= qq{[oneline|expand]}; } else { my $qs = $q->qs(showmsg => 1); - $x = qq{expand}; + $x .= qq{[oneline|expand]}; } - $fh->write("$desc" . - "
$desc\n\n".
-		"Commit Log ($x)\n");
-	$fh->write(@graph && $showmsg ? '
' : "\n"); - my %ac; - local $/ = "\0\0\n"; my $rel = $req->{relcmd}; + $fh->write('' . PublicInbox::Hval::STYLE . + "$desc
$desc\n\n".
+		qq!follow log\t$x\n!);
+	$fh->write($showmsg ? '
' : "\n"); + my %acache; + local $/ = "\0\0\n"; + my $nr = 0; + my (@parents, %seen); while (defined(my $line = <$log>)) { - my @x; - my ($gr, $id, $s, $D, $ai, $an, $b) = @x = split("\0", $line); - - # --graph may output graph-only lines without a commit - unless (defined $id) { - $fh->write($gr . "\n"); - next; - } + my ($id, $p, $s, $D, $ai, $an, $b) = split("\0", $line); + $seen{$id} = 1; + my @p = split(' ', $p); + push @parents, @p; - $s =~ s/\As//; $s = utf8_html($s); $s = qq($s); - if ($D =~ /\AD(.+)/) { $s .= ' ('. join(', ', git_dec_links($rel, $1)) . ')'; } @@ -88,31 +81,44 @@ sub git_log_stream { $b =~ s/\Ab//; $b =~ s/\s*\z//s; - my $ah = $ac{$an} ||= utf8_html($an); - - if (@graph) { - # duplicate the last line of graph as many - # times at it takes to match the number of - # lines in the body: - my $nl = ($b =~ tr/\n/\n/) + 4; - $nl -= ($gr =~ tr/\n/\n/); - $gr =~ s/([^\n]+)\z/($1."\n") x $nl/es; - } - $b = utf8_html($b); - $b = "$s\n- $ah @ $ai\n\n$b"; - if (@graph) { - $fh->write('
'. $gr .
-					'
' . $b .
-					'
'); + my $ah = $acache{$an} ||= utf8_html($an); + my $x = "
";
+			if (@p && $nr) {
+				$x .= qq($id);
 			} else {
-				$fh->write($b. "\n\n");
+				$x .= $id;
 			}
+			my $nl = $b eq '' ? '' : "\n";
+			$b = $x . '  
' .
+				"$s\n- $ah @ $ai\n$nl" .
+				utf8_html($b) . '
'; + } elsif (@p && $nr) { + $b = qq($id\t$s\n); } else { - $fh->write((@graph ? $gr : '') . $s . "\n"); + $b = qq($id\t$s\n); } + $fh->write($b); + ++$nr; } - $fh->write((@graph && $showmsg ? '' : '') . ''); + my $m = ''; + my $np = 0; + foreach my $p (@parents) { + next if $seen{$p}; + $seen{$p} = ++$np; + my $s = git_commit_title($git, $p); + $s = defined($s) ? utf8_html($s) : ''; + $m .= qq(\n$p\t$s); + } + my $foot = $showmsg ? "
\t\t$x\n\n" : "\n\t\t$x\n\n";
+	if ($np == 0) {
+		$foot .= "No commits follow";
+	} elsif ($np > 1) {
+		$foot .= "Parent commits to follow (multiple choice):\n";
+	} else {
+		$foot .= "Next parent:\n";
+	}
+	$fh->write($foot .= $m . '
'); } 1;