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.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF 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 24F091F523 for ; Tue, 4 Oct 2022 19:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1664910761; bh=xyOYu7Oyn9K2PIYsOCp4KuWt6Sf4RB3AX41BpUmSsos=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E7FS9n/6d8Kz0WIUSQdP4FxVYEn7aKSf72a/XKHeT/8c8vAJ6GSnTSRFKEI67w7+f E9AvssE3l0THfRQU6SIsgSVVt56OzF6zXF7RCg7ermTfrvJs+4KgwsF16R5vZ/rVBf uecLx055PkemYlpIeICtzMCqj9OpqVw+0ZRzuXVI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/10] git: hoist out description Date: Tue, 4 Oct 2022 19:12:33 +0000 Message-Id: <20221004191240.1056304-4-e@80x24.org> In-Reply-To: <20221004191240.1056304-1-e@80x24.org> References: <20221004191240.1056304-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We'll be using this separately, elsewhere. --- lib/PublicInbox/Git.pm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 9140caea..78b47096 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -498,6 +498,15 @@ sub modified ($) { (split(/ /, <$fh> // time))[0] + 0; # integerize for JSON } +sub description { + my $desc = ''; + if (open(my $fh, '<:utf8', "$_[0]->{git_dir}/description")) { + local $/ = "\n"; + chomp($desc = <$fh> // ''); + } + $desc eq '' ? 'Unnamed repository' : $desc; +} + # for grokmirror, which doesn't read gitweb.description # templates/hooks--update.sample and git-multimail in git.git # only match "Unnamed repository", not the full contents of @@ -520,14 +529,8 @@ sub manifest_entry { chomp(my $owner = $self->qx('config', 'gitweb.owner')); utf8::decode($owner); $ent->{owner} = $owner eq '' ? undef : $owner; - my $desc = ''; - if (open($fh, '<', "$git_dir/description")) { - local $/ = "\n"; - chomp($desc = <$fh>); - utf8::decode($desc); - } - $desc = 'Unnamed repository' if $desc eq ''; - if (defined $epoch && $desc =~ /\AUnnamed repository/) { + my $desc = description($self); + if (defined $epoch && index($desc, 'Unnamed repository') == 0) { $desc = "$default_desc [epoch $epoch]"; } $ent->{description} = $desc;