# show the log view
package PublicInbox::RepoGitLog;
use strict;
use warnings;
use PublicInbox::Hval qw(utf8_html);
use base qw(PublicInbox::RepoBase);
use PublicInbox::RepoGit qw(git_dec_links git_commit_title);
use PublicInbox::Qspawn;
# cannot rely on --date=format-local:... yet, it is too new (September 2015)
use constant STATES => qw(H p D ai an s b);
use constant STATE_BODY => (scalar(STATES) - 1);
my $LOG_FMT = '--pretty=tformat:'. join('%n', map { "%$_" } STATES).'%x00';
sub parent_links {
if (@_ == 1) { # typical, single-parent commit
qq(\n parent $_[0]);
} elsif (@_ > 0) { # merge commit
"\n parents " .
join("\n ",
map { qq($_) } @_);
} else {
''; # root commit
}
}
sub flush_log_hdr ($$$) {
my ($req, $dst, $hdr) = @_;
my $lpfx = $req->{lpfx};
my $seen = $req->{seen};
$$dst .= '
' if scalar keys %$seen;
my $id = $hdr->{H};
$seen->{$id} = 1;
$$dst .= qq();
$$dst .= utf8_html($hdr->{'s'}); # FIXME may still OOM
$$dst .= '';
my $D = $hdr->{D}; # FIXME: thousands of decorations may OOM us
if ($D ne '') {
$$dst .= ' (' . join(', ', git_dec_links($lpfx, $D)) . ')';
}
my @p = split(/ /, $hdr->{p});
push @{$req->{parents}}, @p;
my $plinks = parent_links(@p);
$$dst .= "\n- ";
$$dst .= utf8_html($hdr->{an});
$$dst .= " @ $hdr->{ai}\n commit $id$plinks\n";
undef
}
sub git_log_sed_end ($$) {
my ($req, $dst) = @_;
$$dst .= '
';
my $m = '';
my $np = 0;
my $seen = $req->{seen};
my $git = $req->{-repo}->{git};
my $lpfx = $req->{lpfx};
foreach my $p (@{$req->{parents}}) {
next if $seen->{$p};
$seen->{$p} = ++$np;
my $s = git_commit_title($git, $p);
$m .= qq(\n$p\t);
$s = defined($s) ? utf8_html($s) : '';
$m .= qq($s);
}
if ($np == 0) {
$$dst .= "No commits follow";
} elsif ($np > 1) {
$$dst .= "Unseen parent commits to follow (multiple choice):\n";
} else {
$$dst .= "Next parent to follow:\n";
}
$$dst .= $m;
$$dst .= '