]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Inbox.pm
www: support cloning individual v2 git partitions
[public-inbox.git] / lib / PublicInbox / Inbox.pm
index b1ea8dc7bce215b06fe3f7a4715d53f7846c3b84..309775146fd1b015383c462e6178650f60dad5b7 100644 (file)
@@ -82,6 +82,18 @@ sub new {
        bless $opts, $class;
 }
 
+sub git_part {
+       my ($self, $part) = @_;
+       ($self->{version} || 1) == 2 or return;
+       $self->{"$part.git"} ||= eval {
+               my $git_dir = "$self->{mainrepo}/git/$part.git";
+               my $g = PublicInbox::Git->new($git_dir);
+               $g->{-httpbackend_limiter} = $self->{-httpbackend_limiter};
+               # no cleanup needed, we never cat-file off this, only clone
+               $g;
+       };
+}
+
 sub git {
        my ($self) = @_;
        $self->{git} ||= eval {
@@ -94,6 +106,29 @@ sub git {
        };
 }
 
+sub max_git_part {
+       my ($self) = @_;
+       my $v = $self->{version};
+       return unless defined($v) && $v == 2;
+       my $part = $self->{-max_git_part};
+       my $changed = git($self)->alternates_changed;
+       if (!defined($part) || $changed) {
+               $self->git->cleanup if $changed;
+               my $gits = "$self->{mainrepo}/git";
+               if (opendir my $dh, $gits) {
+                       my $max = -1;
+                       while (defined(my $git_dir = readdir($dh))) {
+                               $git_dir =~ m!\A(\d+)\.git\z! or next;
+                               $max = $1 if $1 > $max;
+                       }
+                       $part = $self->{-max_git_part} = $max if $max >= 0;
+               } else {
+                       warn "opendir $gits failed: $!\n";
+               }
+       }
+       $part;
+}
+
 sub mm {
        my ($self) = @_;
        $self->{mm} ||= eval {
@@ -133,7 +168,7 @@ sub description {
        local $/ = "\n";
        chomp $desc;
        $desc =~ s/\s+/ /smg;
-       $desc = '($GIT_DIR/description missing)' if $desc eq '';
+       $desc = '($REPO_DIR/description missing)' if $desc eq '';
        $self->{description} = $desc;
 }