href => $feed_opts->{atomurl} ||
"http://example.com/atom.xml",
},
- id => $addr || 'public-inbox@example.com',
+ id => 'mailto:' . ($addr || 'public-inbox@example.com'),
updated => POSIX::strftime(DATEFMT, gmtime),
);
my $old_r = $cgi->param('r');
my $prev = ' ';
my $next = ' ';
- my %opts = (-path => 1, -query => 1, -relative => 1);
if ($last) {
- $cgi->param('r', $last);
- $next = $cgi->url(%opts);
+ $next = $cgi->path_info . "?r=$last";
$next = qq!<a href="$next">next</a>!;
}
if ($first && $old_r) {
- $cgi->param('r', "$first..");
- $prev = $cgi->url(%opts);
+ $prev = $cgi->path_info . "?r=$first..";
$prev = qq!<a href="$prev">prev</a>!;
}
"$prev $next";
sub each_recent_blob {
my ($args, $cb) = @_;
my $max = $args->{max} || MAX_PER_PAGE;
- my $refhex = qr/[a-f0-9]{4,40}(?:~\d+)?/;
+ my $hex = '[a-f0-9]';
+ my $addmsg = qr!^:000000 100644 \S+ \S+ A\t(${hex}{2}/${hex}{38})$!;
+ my $delmsg = qr!^:100644 000000 \S+ \S+ D\t(${hex}{2}/${hex}{38})$!;
+ my $refhex = qr/${hex}{4,40}(?:~\d+)?/;
my $cgi = $args->{cgi};
# revision ranges may be specified
# get recent messages
# we could use git log -z, but, we already know ssoma will not
# leave us with filenames with spaces in them..
- my @cmd = qw/git log --no-notes --no-color --raw -r --no-abbrev/;
+ my @cmd = qw/git log --no-notes --no-color --raw -r/;
push @cmd, '--reverse' if $reverse;
push @cmd, $range;
my $first;
my $pid = open(my $log, '-|', @cmd) or
die('open `'.join(' ', @cmd) . " pipe failed: $!\n");
- my %deleted;
+ my %deleted; # only an optimization at this point
my $last;
my $nr = 0;
my @commits = ();
while (my $line = <$log>) {
- if ($line =~ /^:000000 100644 0{40} ([a-f0-9]{40})/) {
+ if ($line =~ /$addmsg/o) {
my $add = $1;
next if $deleted{$add};
$nr += $cb->($add);
$last = 1;
last;
}
- } elsif ($line =~ /^:100644 000000 ([a-f0-9]{40}) 0{40}/) {
+ } elsif ($line =~ /$delmsg/o) {
$deleted{$1} = 1;
- } elsif ($line =~ /^commit ([a-f0-9]{40})/) {
+ } elsif ($line =~ /^commit (${hex}{40})/) {
push @commits, $1;
}
}
if ($last) {
while (my $line = <$log>) {
- if ($line =~ /^commit ([a-f0-9]{40})/) {
+ if ($line =~ /^commit (${hex}{40})/) {
push @commits, $1;
last;
}
}
my $url_base;
if ($cgi) {
- my $cgi_url = $cgi->url(-path=>1, -relative=>1);
- my $base = $cgi->url(-base);
- $url_base = $cgi_url;
+ my $path_info = $cgi->path_info;
+ my $base;
+ if (ref($cgi) eq 'CGI') {
+ $base = $cgi->url(-base);
+ } else {
+ $base = "${$cgi->base}";
+ $base =~ s!/\z!!;
+ }
+ $url_base = $path_info;
if ($url_base =~ s!/(?:|index\.html)?\z!!) {
$rv{atomurl} = "$base$url_base/atom.xml";
} else {
$url_base =~ s!/atom\.xml\z!!;
- $rv{atomurl} = $base . $cgi_url;
+ $rv{atomurl} = $base . $path_info;
$url_base = $base . $url_base; # XXX is this needed?
}
} else {
my $date = $mime->header('Date');
$date = PublicInbox::Hval->new_oneline($date);
$date = feed_date($date->raw) or return 0;
+ $add =~ tr!/!!d;
+ my $h = '[a-f0-9]';
+ my (@uuid5) = ($add =~ m!\A($h{8})($h{4})($h{4})($h{4})($h{12})!o);
+
$feed->add_entry(
author => { name => $name, email => $email },
title => $subject,
updated => $date,
- content => { type => "html", content => $content },
+ content => { type => 'xhtml', content => $content },
link => $midurl . $href,
- id => $add,
+ id => 'urn:uuid:' . join('-', @uuid5),
);
1;
}
};
sub do_cat_mail {
- my ($git, $sha1) = @_;
+ my ($git, $path) = @_;
my $str;
if ($git) {
open my $fh, '>', \$str or
die "failed to setup string handle: $!\n";
binmode $fh;
- my $bytes = $git->cat_blob($sha1, $fh);
+ my $err = '';
+ my $bytes;
+ {
+ local $SIG{__WARN__} = sub { $err .= $_[0] };
+ $bytes = $git->cat_blob("HEAD:$path", $fh);
+ }
close $fh or die "failed to close string handle: $!\n";
+
+ if ($bytes < 0 && $err &&
+ $err !~ /doesn't exist in the repository/) {
+ warn $err;
+ }
return if $bytes <= 0;
} else {
- $str = `git cat-file blob $sha1`;
+ $str = `git cat-file blob HEAD:$path`;
return if $? != 0 || length($str) == 0;
}
Email::MIME->new($str);