# Copyright (C) 2015 all contributors <meta@public-inbox.org>
# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+#
+# Used only by the NNTP server to represent a public-inbox git repository
+# as a newsgroup
package PublicInbox::NewsGroup;
use strict;
use warnings;
-use fields qw(name git_dir address domain mm gcf search);
use Scalar::Util qw(weaken);
require Danga::Socket;
require PublicInbox::Msgmap;
-require PublicInbox::GitCatFile;
+require PublicInbox::Search;
+require PublicInbox::Git;
sub new {
my ($class, $name, $git_dir, $address) = @_;
- my $self = fields::new($class);
- $self->{name} = $name;
+ $address = $address->[0] if ref($address);
+ my $self = bless {
+ name => $name,
+ git_dir => $git_dir,
+ address => $address,
+ }, $class;
$self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
- $self->{git_dir} = $git_dir;
- $self->{address} = $address;
$self;
}
sub gcf {
my ($self) = @_;
$self->{gcf} ||= eval {
- my $gcf = PublicInbox::GitCatFile->new($self->{git_dir});
+ my $gcf = PublicInbox::Git->new($self->{git_dir});
# git repos may be repacked and old packs unlinked
defer_weaken($self, 'gcf');
};
}
+sub usable {
+ my ($self) = @_;
+ eval {
+ PublicInbox::Msgmap->new($self->{git_dir});
+ PublicInbox::Search->new($self->{git_dir});
+ };
+}
+
sub mm {
- my ($self, $check_only) = @_;
- if ($check_only) {
- return eval { PublicInbox::Msgmap->new($self->{git_dir}) };
- }
+ my ($self) = @_;
$self->{mm} ||= eval {
my $mm = PublicInbox::Msgmap->new($self->{git_dir});
sub search {
my ($self) = @_;
$self->{search} ||= eval {
- require PublicInbox::Search;
my $search = PublicInbox::Search->new($self->{git_dir});
# may be needed if we run low on handles