package PublicInbox::Inbox;
use strict;
use warnings;
-use Scalar::Util qw(weaken);
+use Scalar::Util qw(weaken isweak);
use PublicInbox::Git;
use PublicInbox::MID qw(mid2path);
sub weaken_all {
my ($self) = @_;
- weaken($self->{$_}) foreach qw(git mm search);
+ foreach my $f (qw(git mm search)) {
+ isweak($self->{$f}) or weaken($self->{$f});
+ }
}
sub git {
}
sub base_url {
- my ($self, $prq) = @_; # Plack::Request
- if (defined $prq) {
- my $url = $prq->base->as_string;
- $url .= '/' if $url !~ m!/\z!; # for mount in Plack::Builder
+ my ($self, $env) = @_;
+ if ($env) { # PSGI env
+ my $scheme = $env->{'psgi.url_scheme'};
+ my $host_port = $env->{HTTP_HOST} ||
+ "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
+ my $url = "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/');
+ # for mount in Plack::Builder
+ $url .= '/' if $url !~ m!/\z!;
$url .= $self->{name} . '/';
} else {
# either called from a non-PSGI environment (e.g. NNTP/POP3)
sub msg_by_path ($$;$) {
my ($self, $path, $ref) = @_;
# TODO: allow other refs:
- git($self)->cat_file('HEAD:'.$path, $ref);
+ my $str = git($self)->cat_file('HEAD:'.$path, $ref);
+ $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str;
+ $str;
+}
+
+sub path_check {
+ my ($self, $path) = @_;
+ git($self)->check('HEAD:'.$path);
}
sub msg_by_mid ($$;$) {