about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-10-04 19:12:34 +0000
committerEric Wong <e@80x24.org>2022-10-05 20:24:44 +0000
commita002384a74382df2649d6a1f8dfba4f291af032e (patch)
tree1106206df2c10fc21adec29b1c3dcbcff9075d3d /lib/PublicInbox
parenta93c7e471ca70bdb476c2285cf894e319b38f160 (diff)
downloadpublic-inbox-a002384a74382df2649d6a1f8dfba4f291af032e.tar.gz
We'll be using these functions for serving coderepos natively
without cgit.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/ExtSearch.pm2
-rw-r--r--lib/PublicInbox/Git.pm30
-rw-r--r--lib/PublicInbox/Inbox.pm23
3 files changed, 29 insertions, 26 deletions
diff --git a/lib/PublicInbox/ExtSearch.pm b/lib/PublicInbox/ExtSearch.pm
index a69c0e76..fa49a1d0 100644
--- a/lib/PublicInbox/ExtSearch.pm
+++ b/lib/PublicInbox/ExtSearch.pm
@@ -108,7 +108,7 @@ sub altid_map { {} }
 sub description {
         my ($self) = @_;
         ($self->{description} //=
-                PublicInbox::Inbox::cat_desc("$self->{topdir}/description")) //
+                PublicInbox::Git::cat_desc("$self->{topdir}/description")) //
                 '$EXTINDEX_DIR/description missing';
 }
 
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 78b47096..2f0bb6a0 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -498,13 +498,31 @@ sub modified ($) {
         (split(/ /, <$fh> // time))[0] + 0; # integerize for JSON
 }
 
+sub try_cat {
+        my ($path) = @_;
+        open(my $fh, '<', $path) or return '';
+        local $/;
+        <$fh> // '';
+}
+
+sub cat_desc ($) {
+        my $desc = try_cat($_[0]);
+        chomp $desc;
+        utf8::decode($desc);
+        $desc =~ s/\s+/ /smg;
+        $desc eq '' ? undef : $desc;
+}
+
 sub description {
-        my $desc = '';
-        if (open(my $fh, '<:utf8', "$_[0]->{git_dir}/description")) {
-                local $/ = "\n";
-                chomp($desc = <$fh> // '');
-        }
-        $desc eq '' ? 'Unnamed repository' : $desc;
+        cat_desc("$_[0]->{git_dir}/description") // 'Unnamed repository';
+}
+
+sub cloneurl {
+        my ($self) = @_;
+        $self->{cloneurl} // do {
+                my @urls = split(/\s+/s, try_cat("$self->{git_dir}/cloneurl"));
+                scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef;
+        } // [];
 }
 
 # for grokmirror, which doesn't read gitweb.description
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 8ac7eb30..3532bb58 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -181,33 +181,18 @@ sub over {
         } // ($req ? croak("E: $@") : undef);
 }
 
-sub try_cat {
-        my ($path) = @_;
-        open(my $fh, '<', $path) or return '';
-        local $/;
-        <$fh> // '';
-}
-
-sub cat_desc ($) {
-        my $desc = try_cat($_[0]);
-        local $/ = "\n";
-        chomp $desc;
-        utf8::decode($desc);
-        $desc =~ s/\s+/ /smg;
-        $desc eq '' ? undef : $desc;
-}
-
 sub description {
         my ($self) = @_;
-        ($self->{description} //= cat_desc("$self->{inboxdir}/description")) //
+        ($self->{description} //=
+                PublicInbox::Git::cat_desc("$self->{inboxdir}/description")) //
                 '($INBOX_DIR/description missing)';
 }
 
 sub cloneurl {
         my ($self) = @_;
         $self->{cloneurl} // do {
-                my $s = try_cat("$self->{inboxdir}/cloneurl");
-                my @urls = split(/\s+/s, $s);
+                my @urls = split(/\s+/s,
+                  PublicInbox::Git::try_cat("$self->{inboxdir}/cloneurl"));
                 scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef;
         } // [];
 }