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 22CAA202BB for ; Fri, 5 Apr 2019 20:04:30 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/5] config: support cgit scan-path and scan-hidden-path Date: Fri, 5 Apr 2019 20:04:25 +0000 Message-Id: <20190405200429.16973-2-e@80x24.org> In-Reply-To: <20190405200429.16973-1-e@80x24.org> References: <20190405200429.16973-1-e@80x24.org> List-Id: project_list support still needs to be done And tests need to be written... :< --- lib/PublicInbox/Config.pm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 9c1c3e2..9f1e57a 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -208,6 +208,30 @@ sub cgit_repo_merge ($$) { $self->{"coderepo.$nick.cgiturl"} ||= $nick; } +sub is_git_dir ($) { + my ($git_dir) = @_; + -d "$git_dir/objects" && -f "$git_dir/HEAD"; +} + +sub scan_path_coderepo { + my ($self, $base, $path) = @_; + opendir my $dh, $path or return; + while (defined(my $dn = readdir $dh)) { + next if $dn eq '.' || $dn eq '..'; + if (index($dn, '.') == 0 && !$self->{-cgit_scan_hidden_path}) { + next; + } + my $nick = $base eq '' ? $dn : "$base/$dn"; + my $git_dir = "$path/$dn"; + if (is_git_dir($git_dir)) { + my $repo = { url => $nick, path => $git_dir }; + cgit_repo_merge($self, $repo); + } elsif (-d $git_dir) { + scan_path_coderepo($self, $nick, $git_dir); + } + } +} + sub parse_cgitrc { my ($self, $cgitrc, $nesting) = @_; @@ -235,6 +259,10 @@ sub parse_cgitrc { } } elsif (m!\Ainclude=(.+)\z!) { parse_cgitrc($self, $1, $nesting + 1); + } elsif (m!\Ascan-hidden-path=(\d+)\z!) { + $self->{-cgit_scan_hidden_path} = $1; + } elsif (m!\Ascan-path=(.+)\z!) { + scan_path_coderepo($self, '', $1); } } cgit_repo_merge($self, $repo) if $repo; -- EW