diff options
Diffstat (limited to 'lib/PublicInbox/Repo.pm')
-rw-r--r-- | lib/PublicInbox/Repo.pm | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/PublicInbox/Repo.pm b/lib/PublicInbox/Repo.pm new file mode 100644 index 00000000..e53d6975 --- /dev/null +++ b/lib/PublicInbox/Repo.pm @@ -0,0 +1,47 @@ +# Copyright (C) 2017 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +# +# Represents a code repository, analoguos to the PublicInbox::Inbox +# class for represpenting an inbox git repository. +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; |