about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-27 20:31:44 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-27 21:20:01 +0000
commit7b5ea579e6a9490a4a38958acac8e078d805eec7 (patch)
tree28e99dd0ee8c6740ed0f5aaf22837db31ca983cd /lib/PublicInbox/Inbox.pm
parenta966564fef08a4f25670778efbff139fbbf47c84 (diff)
downloadpublic-inbox-7b5ea579e6a9490a4a38958acac8e078d805eec7.tar.gz
This will require multiple client invocations, but should reduce
load on the server and make it easier for readers to only clone
the latest data.

Unfortunately, supporting a cloneurl file for externally-hosted
repos will be more difficult as we cannot easily know if the
clones use v1 or v2 repositories, or how many git partitions
they have.
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r--lib/PublicInbox/Inbox.pm37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index b1ea8dc7..30977514 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -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;
 }