From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D7D4D2141E for ; Mon, 21 Jan 2019 20:52:54 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/37] git: support multiple URL endpoints Date: Mon, 21 Jan 2019 20:52:21 +0000 Message-Id: <20190121205253.10455-6-e@80x24.org> In-Reply-To: <20190121205253.10455-1-e@80x24.org> References: <20190121205253.10455-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: For redundancy and centralization resistance. --- lib/PublicInbox/Git.pm | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 9676086..a270180 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -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; -- EW