* [PATCH 04/10] git: move cloneurl + description reading here
2022-10-04 19:12 6% [PATCH 00/10] www_coderepo: git viewer w/ search planned Eric Wong
@ 2022-10-04 19:12 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2022-10-04 19:12 UTC (permalink / raw)
To: meta
We'll be using these functions for serving coderepos natively
without cgit.
---
lib/PublicInbox/ExtSearch.pm | 2 +-
lib/PublicInbox/Git.pm | 30 ++++++++++++++++++++++++------
lib/PublicInbox/Inbox.pm | 23 ++++-------------------
t/init.t | 2 +-
t/lei-mirror.t | 10 +++++-----
5 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/lib/PublicInbox/ExtSearch.pm b/lib/PublicInbox/ExtSearch.pm
index a69c0e76..fa49a1d0 100644
--- a/lib/PublicInbox/ExtSearch.pm
+++ b/lib/PublicInbox/ExtSearch.pm
@@ -108,7 +108,7 @@ sub altid_map { {} }
sub description {
my ($self) = @_;
($self->{description} //=
- PublicInbox::Inbox::cat_desc("$self->{topdir}/description")) //
+ PublicInbox::Git::cat_desc("$self->{topdir}/description")) //
'$EXTINDEX_DIR/description missing';
}
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 78b47096..2f0bb6a0 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -498,13 +498,31 @@ sub modified ($) {
(split(/ /, <$fh> // time))[0] + 0; # integerize for JSON
}
+sub try_cat {
+ my ($path) = @_;
+ open(my $fh, '<', $path) or return '';
+ local $/;
+ <$fh> // '';
+}
+
+sub cat_desc ($) {
+ my $desc = try_cat($_[0]);
+ chomp $desc;
+ utf8::decode($desc);
+ $desc =~ s/\s+/ /smg;
+ $desc eq '' ? undef : $desc;
+}
+
sub description {
- my $desc = '';
- if (open(my $fh, '<:utf8', "$_[0]->{git_dir}/description")) {
- local $/ = "\n";
- chomp($desc = <$fh> // '');
- }
- $desc eq '' ? 'Unnamed repository' : $desc;
+ cat_desc("$_[0]->{git_dir}/description") // 'Unnamed repository';
+}
+
+sub cloneurl {
+ my ($self) = @_;
+ $self->{cloneurl} // do {
+ my @urls = split(/\s+/s, try_cat("$self->{git_dir}/cloneurl"));
+ scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef;
+ } // [];
}
# for grokmirror, which doesn't read gitweb.description
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 8ac7eb30..3532bb58 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -181,33 +181,18 @@ sub over {
} // ($req ? croak("E: $@") : undef);
}
-sub try_cat {
- my ($path) = @_;
- open(my $fh, '<', $path) or return '';
- local $/;
- <$fh> // '';
-}
-
-sub cat_desc ($) {
- my $desc = try_cat($_[0]);
- local $/ = "\n";
- chomp $desc;
- utf8::decode($desc);
- $desc =~ s/\s+/ /smg;
- $desc eq '' ? undef : $desc;
-}
-
sub description {
my ($self) = @_;
- ($self->{description} //= cat_desc("$self->{inboxdir}/description")) //
+ ($self->{description} //=
+ PublicInbox::Git::cat_desc("$self->{inboxdir}/description")) //
'($INBOX_DIR/description missing)';
}
sub cloneurl {
my ($self) = @_;
$self->{cloneurl} // do {
- my $s = try_cat("$self->{inboxdir}/cloneurl");
- my @urls = split(/\s+/s, $s);
+ my @urls = split(/\s+/s,
+ PublicInbox::Git::try_cat("$self->{inboxdir}/cloneurl"));
scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef;
} // [];
}
diff --git a/t/init.t b/t/init.t
index 6f4c9dce..460c83f3 100644
--- a/t/init.t
+++ b/t/init.t
@@ -102,7 +102,7 @@ sub quiet_fail {
umask($umask) // xbail "umask: $!";
ok(-d "$tmpdir/a/b/c/d", 'directory created');
my $desc = "$tmpdir/a/b/c/d/description";
- is(PublicInbox::Inbox::try_cat($desc),
+ is(PublicInbox::Git::try_cat($desc),
"public inbox for abcd\@example.com\n", 'description set');
my $mode = (stat($desc))[2];
is(sprintf('0%03o', $mode & 0777), '0644',
diff --git a/t/lei-mirror.t b/t/lei-mirror.t
index 32a5b039..c172483b 100644
--- a/t/lei-mirror.t
+++ b/t/lei-mirror.t
@@ -22,7 +22,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
lei_ok('add-external', $t1, '--mirror', "$http/t1/", \'--mirror v1');
my $mm_dup = "$t1/public-inbox/msgmap.sqlite3";
ok(-f $mm_dup, 't1-mirror indexed');
- is(PublicInbox::Inbox::try_cat("$t1/description"),
+ is(PublicInbox::Git::try_cat("$t1/description"),
"mirror of $http/t1/\n", 'description set');
ok(-f "$t1/Makefile", 'convenience Makefile added (v1)');
ok(-f "$t1/inbox.config.example", 'inbox.config.example downloaded');
@@ -43,7 +43,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
ok(-f $mm_dup, 't2-mirror indexed');
ok(-f "$t2/description", 't2 description');
ok(-f "$t2/Makefile", 'convenience Makefile added (v2)');
- is(PublicInbox::Inbox::try_cat("$t2/description"),
+ is(PublicInbox::Git::try_cat("$t2/description"),
"mirror of $http/t2/\n", 'description set');
$tb = PublicInbox::Msgmap->new_file($mm_dup)->created_at;
is($tb, $created{v2}, 'created_at matched in v2 mirror');
@@ -199,14 +199,14 @@ $td->join;
my $exp = "mirror of https://example.com/src/\n";
my $f = "$tmpdir/description";
PublicInbox::LeiMirror::set_description($mrr);
- is(PublicInbox::Inbox::try_cat($f), $exp, 'description set on ENOENT');
+ is(PublicInbox::Git::try_cat($f), $exp, 'description set on ENOENT');
my $fh;
(open($fh, '>', $f) and close($fh)) or xbail $!;
PublicInbox::LeiMirror::set_description($mrr);
- is(PublicInbox::Inbox::try_cat($f), $exp, 'description set on empty');
+ is(PublicInbox::Git::try_cat($f), $exp, 'description set on empty');
(open($fh, '>', $f) and print $fh "x\n" and close($fh)) or xbail $!;
- is(PublicInbox::Inbox::try_cat($f), "x\n",
+ is(PublicInbox::Git::try_cat($f), "x\n",
'description preserved if non-default');
}
^ permalink raw reply related [relevance 7%]
* [PATCH 00/10] www_coderepo: git viewer w/ search planned
@ 2022-10-04 19:12 6% Eric Wong
2022-10-04 19:12 7% ` [PATCH 04/10] git: move cloneurl + description reading here Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2022-10-04 19:12 UTC (permalink / raw)
To: meta
This is to eventually support M:N inbox:coderepo search via
-extindex. For now, it's a JS-free and CSS-optional
cgit-like UI, but perhaps more brutalist :>
It's mainly for wiring /$INBOX/$OID/s/ into /$CODEREPO/$OID/s/,
but Atom feeds and such will be supported.
It'll work better with coderepos with a ".git" name suffix
to avoid conflicts with the inbox name. So [coderepo "git"]
becomes [coderepo "git.git"] in my config file. cgitrc usage
should continue working, I think...
It looks better out-of-the-box on w3m since cgit relies too
much on CSS :>
Example here: https://80x24.org/lore/git.git
Eric Wong (10):
tests: use test_httpd consistently
cgit: use Perl 5.10-isms, optimize, and golf
git: hoist out description
git: move cloneurl + description reading here
www_coderepo: an alternative to cgit
www_coderepo: wire up /$CODEREPO/$OID/s/ endpoint
git: allow ->local_nick to return undef
www_coderepo: wire up snapshot support
www_stream: use git->pub_urls for coderepo links
www_coderepo: start a top nav bar in summary view
MANIFEST | 2 +
lib/PublicInbox/Cgit.pm | 33 ++---
lib/PublicInbox/Config.pm | 2 +-
lib/PublicInbox/ExtSearch.pm | 2 +-
lib/PublicInbox/Git.pm | 53 +++++++--
lib/PublicInbox/GitAsyncCat.pm | 66 ++++++++--
lib/PublicInbox/Inbox.pm | 23 +---
lib/PublicInbox/RepoSnapshot.pm | 95 +++++++++++++++
lib/PublicInbox/SolverGit.pm | 8 +-
lib/PublicInbox/TestCommon.pm | 14 ++-
lib/PublicInbox/ViewVCS.pm | 1 +
lib/PublicInbox/WWW.pm | 12 +-
lib/PublicInbox/WwwCoderepo.pm | 205 ++++++++++++++++++++++++++++++++
lib/PublicInbox/WwwStream.pm | 33 ++---
t/init.t | 2 +-
t/lei-mirror.t | 10 +-
t/psgi_attach.t | 13 +-
t/solver_git.t | 70 ++++++++---
t/www_altid.t | 13 +-
xt/solver.t | 18 +--
20 files changed, 533 insertions(+), 142 deletions(-)
create mode 100644 lib/PublicInbox/RepoSnapshot.pm
create mode 100644 lib/PublicInbox/WwwCoderepo.pm
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2022-10-04 19:12 6% [PATCH 00/10] www_coderepo: git viewer w/ search planned Eric Wong
2022-10-04 19:12 7% ` [PATCH 04/10] git: move cloneurl + description reading here Eric Wong
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).