user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 03/10] git: hoist out description
Date: Tue,  4 Oct 2022 19:12:33 +0000	[thread overview]
Message-ID: <20221004191240.1056304-4-e@80x24.org> (raw)
In-Reply-To: <20221004191240.1056304-1-e@80x24.org>

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;

  parent reply	other threads:[~2022-10-04 19:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04 19:12 [PATCH 00/10] www_coderepo: git viewer w/ search planned Eric Wong
2022-10-04 19:12 ` [PATCH 01/10] tests: use test_httpd consistently Eric Wong
2022-10-04 19:12 ` [PATCH 02/10] cgit: use Perl 5.10-isms, optimize, and golf Eric Wong
2022-10-04 19:12 ` Eric Wong [this message]
2022-10-04 19:12 ` [PATCH 04/10] git: move cloneurl + description reading here Eric Wong
2022-10-04 19:12 ` [PATCH 05/10] www_coderepo: an alternative to cgit Eric Wong
2022-10-04 19:12 ` [PATCH 06/10] www_coderepo: wire up /$CODEREPO/$OID/s/ endpoint Eric Wong
2022-10-04 19:12 ` [PATCH 07/10] git: allow ->local_nick to return undef Eric Wong
2022-10-04 19:12 ` [PATCH 08/10] www_coderepo: wire up snapshot support Eric Wong
2022-10-04 19:12 ` [PATCH 09/10] www_stream: use git->pub_urls for coderepo links Eric Wong
2022-10-04 23:01   ` [PATCH 11/10] www_stream: pass $env to git->pub_urls Eric Wong
2022-10-04 19:12 ` [PATCH 10/10] www_coderepo: start a top nav bar in summary view Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221004191240.1056304-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).