about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-02-11 00:41:29 +0000
committerEric Wong <e@80x24.org>2017-02-11 01:08:08 +0000
commit60f38818f2dbc76e20041cf1b01e2baf3322a1f1 (patch)
tree716820a77859e878a66836309aeefd946b009c5b
parent416ba2fdab4f6de20ad7ec3656a057bb01b17339 (diff)
downloadpublic-inbox-60f38818f2dbc76e20041cf1b01e2baf3322a1f1.tar.gz
This improves startup speed at the cost of CoW-friendliness
for long-lived daemons (which can be fixed, later).
-rw-r--r--lib/PublicInbox/Repo.pm32
-rw-r--r--lib/PublicInbox/RepoBase.pm2
-rw-r--r--lib/PublicInbox/RepoConfig.pm10
-rw-r--r--lib/PublicInbox/RepoGitAtom.pm3
-rw-r--r--lib/PublicInbox/RepoRoot.pm4
5 files changed, 37 insertions, 14 deletions
diff --git a/lib/PublicInbox/Repo.pm b/lib/PublicInbox/Repo.pm
index 812b1071..e53d6975 100644
--- a/lib/PublicInbox/Repo.pm
+++ b/lib/PublicInbox/Repo.pm
@@ -6,10 +6,42 @@
 package PublicInbox::Repo;
 use strict;
 use warnings;
+use PublicInbox::Config;
 
 sub new {
         my ($class, $opts) = @_;
         bless $opts, $class;
 }
 
+sub description {
+        my ($self) = @_;
+        my $desc = $self->{description};
+        return $desc if defined $desc;
+        $desc = PublicInbox::Config::try_cat("$self->{path}/description");
+        local $/ = "\n";
+        chomp $desc;
+        $desc =~ s/\s+/ /smg;
+        $desc = '($GIT_DIR/description missing)' if $desc eq '';
+        $self->{description} = $desc;
+}
+
+sub desc_html {
+        my ($self) = @_;
+        $self->{desc_html} ||=
+                PublicInbox::Hval->utf8($self->description)->as_html;
+}
+
+sub cloneurl {
+        my ($self) = @_;
+        my $url = $self->{cloneurl};
+        return $url if $url;
+        if ($self->{vcs} eq 'git') {
+                $url = PublicInbox::Config::try_cat("$self->{path}/cloneurl");
+                $url = [ split(/\s+/s, $url) ];
+                local $/ = "\n";
+                chomp @$url;
+        }
+        $self->{cloneurl} = $url;
+}
+
 1;
diff --git a/lib/PublicInbox/RepoBase.pm b/lib/PublicInbox/RepoBase.pm
index e60677d6..97f13b25 100644
--- a/lib/PublicInbox/RepoBase.pm
+++ b/lib/PublicInbox/RepoBase.pm
@@ -59,7 +59,7 @@ sub mime_type {
 # starts an HTML page for Repobrowse in a consistent way
 sub html_start {
         my ($self, $req, $title_html, $opts) = @_;
-        my $desc = $req->{repo_info}->{desc_html};
+        my $desc = $req->{repo_info}->desc_html;
         my $meta = '';
 
         if ($opts) {
diff --git a/lib/PublicInbox/RepoConfig.pm b/lib/PublicInbox/RepoConfig.pm
index fb1fd584..e1e2860b 100644
--- a/lib/PublicInbox/RepoConfig.pm
+++ b/lib/PublicInbox/RepoConfig.pm
@@ -30,8 +30,6 @@ sub default_file {
 # Returns something like:
 # {
 #        path => '/home/git/foo.git',
-#        description => 'foo repo',
-#        cloneurl => "git://example.com/foo.git\nhttp://example.com/foo.git",
 #        publicinbox => '/home/pub/foo-public.git',
 # }
 sub lookup {
@@ -51,14 +49,6 @@ sub lookup {
         $rv->{snapshot_re} = qr/\A\Q$snap\E[-_]/;
         $rv->{snapshot_pfx} = $snap;
 
-        # gitweb compatibility
-        foreach my $key (qw(description cloneurl)) {
-                $rv->{$key} = PublicInbox::Config::try_cat("$path/$key");
-        }
-
-        $rv->{desc_html} =
-                PublicInbox::Hval->new_oneline($rv->{description})->as_html;
-
         foreach my $key (qw(publicinbox vcs readme group snapshots)) {
                 $rv->{$key} = $self->{"repo.$repo_path.$key"};
         }
diff --git a/lib/PublicInbox/RepoGitAtom.pm b/lib/PublicInbox/RepoGitAtom.pm
index a9f40126..6d0caa02 100644
--- a/lib/PublicInbox/RepoGitAtom.pm
+++ b/lib/PublicInbox/RepoGitAtom.pm
@@ -70,10 +70,11 @@ sub git_atom_sed ($$) {
         $title = utf8_html("$title, branch $req->{q}->{h}");
         my $url = repo_root_url($self, $req);
         my $hdr = {};
+        my $subtitle = $repo_info->desc_html;
         $req->{axml} = qq(<?xml version="1.0"?>\n) .
                 qq(<feed\nxmlns="http://www.w3.org/2005/Atom">) .
                 qq(<title>$title</title>) .
-                qq(<subtitle>$repo_info->{desc_html}</subtitle>) .
+                qq(<subtitle>$subtitle</subtitle>) .
                 qq(<link\nrel="alternate"\ntype="text/html"\nhref="$url"\n/>);
         my ($plinks, $id, $ai);
         my $end = '';
diff --git a/lib/PublicInbox/RepoRoot.pm b/lib/PublicInbox/RepoRoot.pm
index 9ab25b97..c04c23c5 100644
--- a/lib/PublicInbox/RepoRoot.pm
+++ b/lib/PublicInbox/RepoRoot.pm
@@ -46,7 +46,7 @@ sub repobrowse_index {
                 my $l = $p->as_html;
                 $p = $p->as_path;
                 $fh->write(qq(<tr><td><tt><a\nhref="$p">$l</a></tt></td>) .
-                        "<td><tt> $r->{desc_html}</tt></td></tr>");
+                        '<td><tt> '.$r->desc_html.'</tt></td></tr>');
         }
 
         foreach my $group (keys %$groups) {
@@ -61,7 +61,7 @@ sub repobrowse_index {
                         $p = $p->as_path;
                         $fh->write('<tr><td><tt> ' .
                                 qq(<a\nhref="$p">$l</a></tt></td>) .
-                                "<td><tt> $r->{desc_html}</tt></td></tr>");
+                                '<td><tt> '.$r->desc_html.'</tt></td></tr>');
                 }
         }