use Email::MIME;
use Date::Parse qw(strptime str2time);
use PublicInbox::Hval;
-eval { require Git }; # this is GPLv2+, so we are OK to use it
+use PublicInbox::GitCatFile;
use constant {
- DATEFMT => '%Y-%m-%dT%H:%M:%SZ',
- MAX_PER_PAGE => 25,
+ DATEFMT => '%Y-%m-%dT%H:%M:%SZ', # atom standard
+ MAX_PER_PAGE => 25, # this needs to be tunable
};
-# FIXME: workaround https://rt.cpan.org/Public/Bug/Display.html?id=22817
-
# main function
sub generate {
my ($class, $args) = @_;
require POSIX;
my $max = $args->{max} || MAX_PER_PAGE;
- local $ENV{GIT_DIR} = $args->{git_dir};
my $feed_opts = get_feedopts($args);
my $addr = $feed_opts->{address};
$addr = $addr->[0] if ref($addr);
updated => POSIX::strftime(DATEFMT, gmtime),
);
- my $git = try_git_pm($args->{git_dir});
+ my $git = PublicInbox::GitCatFile->new($args->{git_dir});
each_recent_blob($args, sub {
my ($add) = @_;
add_to_feed($feed_opts, $feed, $add, $git);
});
+ $git = undef; # destroy pipes
+ Email::Address->purge_cache;
$feed->as_string;
}
sub generate_html_index {
my ($class, $args) = @_;
- require Mail::Thread;
+ require PublicInbox::Thread;
my $max = $args->{max} || MAX_PER_PAGE;
- local $ENV{GIT_DIR} = $args->{git_dir};
my $feed_opts = get_feedopts($args);
my $title = $feed_opts->{description} || '';
$title = PublicInbox::Hval->new_oneline($title)->as_html;
my @messages;
- my $git = try_git_pm($args->{git_dir});
+ my $git = PublicInbox::GitCatFile->new($args->{git_dir});
my $last = each_recent_blob($args, sub {
my $mime = do_cat_mail($git, $_[0]) or return 0;
$mime->body_set(''); # save some memory
push @messages, $mime;
1;
});
+ $git = undef; # destroy pipes.
- my $th = Mail::Thread->new(@messages);
+ my $th = PublicInbox::Thread->new(@messages);
$th->thread;
my $html = "<html><head><title>$title</title>" .
'<link rel="alternate" title="Atom feed" href="' .
});
dump_html_line($_, 0, \$html) for $th->rootset;
+ Email::Address->purge_cache;
+
my $footer = nav_footer($args->{cgi}, $last);
$footer = "<hr /><pre>$footer</pre>" if $footer;
$html . "</pre>$footer</html>";
# 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/;
+ my @cmd = ('git', "--git-dir=$args->{git_dir}",
+ qw/log --no-notes --no-color --raw -r/);
push @cmd, $range;
my $pid = open(my $log, '-|', @cmd) or
defined $mid or return 0;
$mid = PublicInbox::Hval->new_msgid($mid);
my $href = $mid->as_href . '.html';
- my $content = PublicInbox::View->as_feed_entry($mime, $fullurl . $href);
+ my $content = PublicInbox::View->feed_entry($mime, $fullurl . $href);
defined($content) or return 0;
my $subject = mime_header($mime, 'Subject') or return 0;
dump_html_line($self->next, $level, $html) if $self->next;
}
-sub try_git_pm {
- my ($dir) = @_;
- eval { Git->repository(Directory => $dir) };
-};
-
sub do_cat_mail {
my ($git, $path) = @_;
- my $str;
- if ($git) {
- open my $fh, '>', \$str or
- die "failed to setup string handle: $!\n";
- binmode $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 HEAD:$path`;
- return if $? != 0 || length($str) == 0;
- }
+ my $str = $git->cat_file("HEAD:$path");
Email::MIME->new($str);
}