]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: support multiple URL endpoints
authorEric Wong <e@80x24.org>
Wed, 16 Jan 2019 21:53:07 +0000 (21:53 +0000)
committerEric Wong <e@80x24.org>
Sat, 19 Jan 2019 03:34:54 +0000 (03:34 +0000)
For redundancy and centralization resistance.

lib/PublicInbox/Git.pm

index 9676086f648d4482d548640d7bc17c01144caff3..a270180caebf11b1c7d07843f4e5c1a0c73c2745 100644 (file)
@@ -202,19 +202,33 @@ sub packed_bytes {
 
 sub DESTROY { cleanup(@_) }
 
+sub local_nick ($) {
+       my ($self) = @_;
+       my $ret = '???';
+       # don't show full FS path, basename should be OK:
+       if ($self->{git_dir} =~ m!/([^/]+)(?:/\.git)?\z!) {
+               $ret = "/path/to/$1";
+       }
+       wantarray ? ($ret) : $ret;
+}
+
 # show the blob URL for cgit/gitweb/whatever
 sub src_blob_url {
        my ($self, $oid) = @_;
-       # blob_fmt = "https://example.com/foo.git/blob/%s"
-       if (my $bfu = $self->{blob_fmt_url}) {
-               return sprintf($bfu, $oid);
+       # blob_url_format = "https://example.com/foo.git/blob/%s"
+       if (my $bfu = $self->{blob_url_format}) {
+               return map { sprintf($_, $oid) } @$bfu if wantarray;
+               return sprintf($bfu->[0], $oid);
        }
+       local_nick($self);
+}
 
-       # don't show full FS path, basename should be OK:
-       if ($self->{git_dir} =~ m!/([^/]+)\z!) {
-               return "/path/to/$1";
+sub pub_urls {
+       my ($self) = @_;
+       if (my $urls = $self->{cgit_url}) {
+               return @$urls;
        }
-       '???';
+       local_nick($self);
 }
 
 1;