]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
4 years agotreewide: "require" + "use" cleanup and docs
Eric Wong [Sun, 5 Jan 2020 23:23:35 +0000 (23:23 +0000)]
treewide: "require" + "use" cleanup and docs

There's a bunch of leftover "require" and "use" statements we no
longer need and can get rid of, along with some excessive
imports via "use".

IO::Handle usage isn't always obvious, so add comments
describing why a package loads it.  Along the same lines,
document the tmpdir support as the reason we depend on
File::Temp 0.19, even though every Perl 5.10.1+ user has it.

While we're at it, favor "use" over "require", since it it gives
us extra compile-time checking.

4 years agoadmin: do not lazy-load Inbox or Config packages
Eric Wong [Sun, 5 Jan 2020 23:23:34 +0000 (23:23 +0000)]
admin: do not lazy-load Inbox or Config packages

No point in lazy-loading these, since they're always loaded
anyways and would not have portability problems on systems with
minimal dependencies.

4 years agoaltid: use msgmap at compile time
Eric Wong [Sun, 5 Jan 2020 23:23:33 +0000 (23:23 +0000)]
altid: use msgmap at compile time

AltId requires Msgmap to work, which requires SQLite.  Search
also requires SQLite3 (for Over), nowadays, so there's no reason
for us to lazy-load Msgmap and SQLite anymore.

4 years agoview: update POSIX::strftime usage
Eric Wong [Sun, 5 Jan 2020 23:23:32 +0000 (23:23 +0000)]
view: update POSIX::strftime usage

The POSIX module is always loaded, so import `strftime' into the
namespace so we can use it and take advantage of compile-time
arg checking.  While we're at it, update and reorder caller
functions to use prototypes, too.

4 years agohval: export prurl and add prototype
Eric Wong [Sun, 5 Jan 2020 23:23:31 +0000 (23:23 +0000)]
hval: export prurl and add prototype

This allows to do some compile-time checking and fills in a
missing "use" in PublicInbox::NewsWWW, allowing it to be used
standalone and independently of PublicInbox::WWW

4 years agot/nntp.t: fix parse_time test for non-GMT local time
Eric Wong [Mon, 6 Jan 2020 04:47:52 +0000 (22:47 -0600)]
t/nntp.t: fix parse_time test for non-GMT local time

Yes, there's actually other timezones!

4 years agowwwstatic: use sprintf for Perl <5.22 compatibility
Eric Wong [Mon, 6 Jan 2020 05:31:07 +0000 (05:31 +0000)]
wwwstatic: use sprintf for Perl <5.22 compatibility

We only declare a Perl 5.10.1+ requirement, and POSIX::lround
was not added until 5.21.4 (5.22.0 for stable releases).

4 years agoview: msg_html: reduce memory use on reused MIDs
Eric Wong [Sun, 5 Jan 2020 09:51:16 +0000 (09:51 +0000)]
view: msg_html: reduce memory use on reused MIDs

In rare cases where Message-IDs get reused, we do not want to
hold onto the large Email::MIME objects in memory after showing
the first message.  So discard each message as soon as we're
done using it so we can save memory for the next message.

The new and expensive xt/mem-msgview.t test shows a nearly 14MB
reduction for two ~7MB messages.  run_script() also gets
upgraded to make it easier to pass large inputs via IO GLOBs.

4 years agotests: remove some "git config" calls after "git init"
Eric Wong [Sat, 4 Jan 2020 22:54:00 +0000 (22:54 +0000)]
tests: remove some "git config" calls after "git init"

Creating a hash and iterating through it just to run "git
config" is ugly and slow.  Just write out the text file in a
human-friendly way since the git-config file format is stable
and won't break randomly.

4 years agosearch: remove lookup_article
Eric Wong [Sat, 4 Jan 2020 22:14:22 +0000 (22:14 +0000)]
search: remove lookup_article

It was no longer used outside of tests, so don't penalize
regular users with the extra function.  Just inline it for
t/search.t.

4 years agotests: fix running without SQLite or Xapian
Eric Wong [Sat, 4 Jan 2020 21:37:52 +0000 (21:37 +0000)]
tests: fix running without SQLite or Xapian

PublicInbox::Search always loads DBD::SQLite, so we
can't blindly "use" it in t/xcpdb-reshard.t.  We also
need to account for that in TestCommon.

4 years agoviewdiff: do not anchor spaces after filenames in diffstat
Eric Wong [Sat, 4 Jan 2020 09:16:21 +0000 (09:16 +0000)]
viewdiff: do not anchor spaces after filenames in diffstat

Viewing a CSS-less page in a browser which underlines links
can show a long line of underscores after diffstats.  Not all
browsers underline links by default, though.

4 years agosearchidx: remove_message: pedantic fix for v1
Eric Wong [Fri, 3 Jan 2020 08:46:03 +0000 (08:46 +0000)]
searchidx: remove_message: pedantic fix for v1

It shouldn't be possible for v1 inboxes to have multiple matches
for a given Message-ID, so the sub would only get called once,
but strange things could happen in 2112 :>

4 years agosearchidx: index_text: use Xapian parameter names
Eric Wong [Fri, 3 Jan 2020 08:46:02 +0000 (08:46 +0000)]
searchidx: index_text: use Xapian parameter names

Use the parameter names from the Search::Xapian::TermGenerator
manpage for our local variables instead of confusing names...

4 years agosearchidx: simplify quote-splitting in index_body
Eric Wong [Fri, 3 Jan 2020 08:46:01 +0000 (08:46 +0000)]
searchidx: simplify quote-splitting in index_body

We now use the same regexp View::add_text_body uses.

4 years agosearchidx: add_message: fix and make use of prototypes
Eric Wong [Fri, 3 Jan 2020 08:46:00 +0000 (08:46 +0000)]
searchidx: add_message: fix and make use of prototypes

Procedural function calls allow prototype checking, and
our add_message prototype was totally wrong to begin with.
Convert most of the "$self->index_*" calls to "index_*($self"

While we're at it, use "//=" to avoid some "unless" statements.

4 years agosearchidx: split off index_xapian for msg_iter
Eric Wong [Fri, 3 Jan 2020 08:45:59 +0000 (08:45 +0000)]
searchidx: split off index_xapian for msg_iter

This ought to save some memory, but it's probably lost in the
noise given the cost of indexing.  Regardless it still reduces
the indentation level and makes future changes easier to read.

4 years agosearchidx: index_diff: allow /^$/ line as diff context
Eric Wong [Fri, 3 Jan 2020 08:45:58 +0000 (08:45 +0000)]
searchidx: index_diff: allow /^$/ line as diff context

As discovered by solver bug hunting, "git apply" also handles
the case where blank lines w/o leading space are treated as diff
context, apparently because GNU diff once did it:

https://public-inbox.org/git/b507b465f7831612b9d9fc643e3e5218b64e5bfa/s/

4 years agosolver: allow literal '\r' character in diff lines
Eric Wong [Sat, 4 Jan 2020 04:19:33 +0000 (04:19 +0000)]
solver: allow literal '\r' character in diff lines

While filenames are escaped, the actual diff contents may
contain an unescaped "\r" carriage return byte not in front
of the "\n" line feed.  So just allow "\r" to appear in the
middle of a line.

4 years agosolver: minor cleanups to diff extraction
Eric Wong [Sat, 4 Jan 2020 03:34:15 +0000 (03:34 +0000)]
solver: minor cleanups to diff extraction

Initialize the $di hashref at use to make it more obvious it's
a local variable.  We can also use the :utf8 IO layer via
open+print to save ourselves the trouble of converting the UTF-8
patch to an octet stream.

4 years agosolver: do not enforce order on extended headers
Eric Wong [Sat, 4 Jan 2020 03:34:14 +0000 (03:34 +0000)]
solver: do not enforce order on extended headers

This is needed to work with patches with many renames,
such as what makes "git/eebf7a8/s/?b=t%2Ftest-lib.sh"

4 years agoxt/solver.t: real-world regression tests
Eric Wong [Sat, 4 Jan 2020 03:34:13 +0000 (03:34 +0000)]
xt/solver.t: real-world regression tests

There's a lot of test cases which we should probably
make self-contained at some point, but right now it's
easier to just mark them off in a maintainer test.

4 years agoqspawn: use per-call quiet flag for solver
Eric Wong [Thu, 2 Jan 2020 09:24:59 +0000 (09:24 +0000)]
qspawn: use per-call quiet flag for solver

solver can spawn multiple processes per HTTP request, but
"git apply" failures are needlessly noisy due to corrupt
patches.  We also don't want to silence "git ls-files"
or "git update-index" errors using $env->{'qspawn.quiet'},
either, so this granularity is needed.

Admins can check for 500 errors in access logs to detect
(and reproduce) solver failures, anyways, so there's no
need to log every time "git apply" rejects a corrupt patch.

4 years agosolver: extract_diff: deal with missing "diff --git" line
Eric Wong [Fri, 3 Jan 2020 00:56:05 +0000 (00:56 +0000)]
solver: extract_diff: deal with missing "diff --git" line

Rewrite the patch extraction loop using a single regexp which
accounts for missing "diff --git ..." lines and is capable of
extracting pathnames off the "+++ b/foo" line.

This fixes the solving of blob "96f1c7f" off
<2841d2de-32ad-eae8-6039-9251a40bb00e@tngtech.com>
in git@vger archives.

v2:

* Fix regressions in git@vger archives:
  - git/776fa90f7f/s/?b=contrib/git-jump/git-jump
    (fallback to "old mode" properly)
  - git/5cd8845/s/?b=submodule.c
    (no leading space in context)

* use "state" in a Perl <5.28.0-compatible way

4 years agosolver: try the next patch on apply failures
Eric Wong [Thu, 2 Jan 2020 09:24:57 +0000 (09:24 +0000)]
solver: try the next patch on apply failures

Sometimes a patch is corrupted and resent to create the same
OID.  We need to account for that case and actually move onto
the next patch instead of blindly trying "git ls-files" to get
nothing out of it.

4 years agobuild: allow "check" to work in non-git subdirs of worktrees
Eric Wong [Thu, 2 Jan 2020 23:29:28 +0000 (23:29 +0000)]
build: allow "check" to work in non-git subdirs of worktrees

Some people will place the contents of an unpacked tarball
inside another directory controlled by git (e.g. a ports tree
or even git-versioned home directory).  "git ls-files" will
succeed in those cases, so we must check for the existence
of a ".git" dir, instead.

4 years agoexamples: add empty "lib" dir to placate plackup
Eric Wong [Thu, 2 Jan 2020 20:09:39 +0000 (20:09 +0000)]
examples: add empty "lib" dir to placate plackup

This is necessary for Filesys::Notify::Simple 0.13 using
Linux::Inotify2, since 0.13 started croaking on
inotify_add_watch failures.

4 years agoconfig: support multi-value inbox.*.*url
Eric Wong [Thu, 2 Jan 2020 03:09:30 +0000 (03:09 +0000)]
config: support multi-value inbox.*.*url

Since the beginning of this project, we've implicitly supported
inboxes with multiple URLs by relying on the Host: header sent
by the client ($env->{HTTP_HOST}).

We now offer the option to explicitly configure multiple URLs for
every inbox along with the ability to do a best-effort match for
matching hostnames.

4 years agowwwlisting: show configured "infourl" properly
Eric Wong [Thu, 2 Jan 2020 03:09:29 +0000 (03:09 +0000)]
wwwlisting: show configured "infourl" properly

git's config file keys lack underscores, but my mind is wired
for underscores :x.  Fix the whitespace around the info URL
while we're at it, so that it shows up right under the inbox
description.

4 years agodoc: fix a few spelling errors in user-facing docs
Eric Wong [Wed, 1 Jan 2020 09:57:55 +0000 (09:57 +0000)]
doc: fix a few spelling errors in user-facing docs

Found by codespell, there's a few more in comments and some
debatable ones, but user-facing stuff is more important.

4 years agobuild: fix xapian-* manpage generation
Eric Wong [Wed, 1 Jan 2020 09:57:54 +0000 (09:57 +0000)]
build: fix xapian-* manpage generation

extman.perl requires the name of its target

4 years agodoc/txt2pre: flush output before utime()
Eric Wong [Wed, 1 Jan 2020 09:57:53 +0000 (09:57 +0000)]
doc/txt2pre: flush output before utime()

Otherwise our utime() change is overridden when the flush
happens at exit.

4 years agodoc: release notes: set Date for 1.2.0, start 1.3.0
Eric Wong [Wed, 1 Jan 2020 09:57:52 +0000 (09:57 +0000)]
doc: release notes: set Date for 1.2.0, start 1.3.0

Seems like a lot's happened since 1.2, but it's mostly
internal stuff...

4 years agobuild: remove NEWS from dist-git target
Eric Wong [Wed, 1 Jan 2020 09:57:51 +0000 (09:57 +0000)]
build: remove NEWS from dist-git target

mknews doesn't require any optional dependencies a user wouldn't
normally have.  We can save storage and bandwidth costs by
letting cgit serve the exact tar.gz which "git archive | gzip -n"
generates.

4 years agodoc: allow NEWS file to be built without Plack::Util
Eric Wong [Wed, 1 Jan 2020 09:57:50 +0000 (09:57 +0000)]
doc: allow NEWS file to be built without Plack::Util

Plack pulls in a lot of dependencies which can be time-consuming
to install.  It should not be necessary for somebody who just
wants to run -mda/-watch and -nntpd and forego WWW.

4 years agowwwstatic: add directory listing + index.html support
Eric Wong [Wed, 1 Jan 2020 10:38:59 +0000 (10:38 +0000)]
wwwstatic: add directory listing + index.html support

It's now possible to use WwwStatic as a standalone PSGI
app to serve static files and recreate the award-winning
web design of https://public-inbox.org/ :>

4 years agowwwstatic: avoid TOCTTOU for FIFO check
Eric Wong [Wed, 1 Jan 2020 10:38:58 +0000 (10:38 +0000)]
wwwstatic: avoid TOCTTOU for FIFO check

We can use Perl's sysopen function to pass O_NONBLOCK to open(2)
and avoid blocking on FIFOs.  This avoids a TOCTTOU race where
somebody can change a regular to FIFO in between the stat(2) and
open(2) syscalls.

4 years agowwwstatic: do not open() files for HEAD requests
Eric Wong [Wed, 1 Jan 2020 10:38:57 +0000 (10:38 +0000)]
wwwstatic: do not open() files for HEAD requests

open() is a much more expensive syscall than stat(),
so avoid it

4 years agowwwstatic: move r(...) functions here
Eric Wong [Wed, 1 Jan 2020 10:38:56 +0000 (10:38 +0000)]
wwwstatic: move r(...) functions here

Remove redundant "r" functions for generating short error
responses.  These responses will no longer be cached by clients,
which is probably a good thing since most errors ought to be
transient, anyways.  This also fixes error responses for our
cgit wrapper when static files are missing.

4 years agowww: move more logic into path_info_raw
Eric Wong [Wed, 1 Jan 2020 10:38:55 +0000 (10:38 +0000)]
www: move more logic into path_info_raw

It'll be easier to reuse in future code.

4 years agowwwstatic: implement Last-Modified and If-Modified-Since
Eric Wong [Wed, 1 Jan 2020 10:38:54 +0000 (10:38 +0000)]
wwwstatic: implement Last-Modified and If-Modified-Since

We're already serving static files for cgit, and will serve more
static files, soon.

4 years agocgit: type declaration for PublicInbox::Git
Eric Wong [Tue, 31 Dec 2019 10:30:13 +0000 (10:30 +0000)]
cgit: type declaration for PublicInbox::Git

AFAIK this doesn't do anything for Perl internally since
PublicInbox::Git doesn't "use fields", but it makes it easier for
humans readers to follow and ensure we're not passing unblessed
or non-ref scalars to PublicInbox::GitHTTPBackend::serve.

4 years agofilter/base: export REJECT as a constant
Eric Wong [Tue, 31 Dec 2019 10:30:12 +0000 (10:30 +0000)]
filter/base: export REJECT as a constant

And update callers to use it, as it makes the code a bit cleaner.
Probably irrelvant, but it should be faster, too, as
"perl -I lib -w -MO=Deparse $FILE" shows REJECT() calls are
constant-folded.

4 years agogithttpbackend: remove ancient compatibility check
Eric Wong [Tue, 31 Dec 2019 10:30:11 +0000 (10:30 +0000)]
githttpbackend: remove ancient compatibility check

The ref() call could be hitting memory leaks on Perl 5.16.x.

It's been 3 years (2016-12-25) since 292ca34140489da2
("githttpbackend: simplify compatibility code") back when
this project was barely known and probably nobody used
examples/public-inbox.psgi...

4 years agohttp: update comment about psgix.io usage
Eric Wong [Tue, 31 Dec 2019 10:30:10 +0000 (10:30 +0000)]
http: update comment about psgix.io usage

We've been using async_pass for a while.

4 years agowwwstatic: getline: die on missing psgix.io
Eric Wong [Tue, 31 Dec 2019 10:30:09 +0000 (10:30 +0000)]
wwwstatic: getline: die on missing psgix.io

"psgix." extensions aren't guaranteed, so make we should
try and support some theoretical generic PSGI servers
without "psgix.io" on errors by die-ing.

While we're at it, make the error handling path more obvious by
sharing more code between the EOF and errno ($!) cases.

4 years agospamcheck/spamc: pass GLOB handles instead of FD numbers
Eric Wong [Tue, 31 Dec 2019 22:34:16 +0000 (22:34 +0000)]
spamcheck/spamc: pass GLOB handles instead of FD numbers

The spawn() interface improvements[1] propagate to popen_rd,
too, so we can avoid weird dances to keep the GLOB handle
references live and just pass the handle around.

[1] commit 267371b1273b518215939e817e53733584b68af7
    ("spawn: allow passing GLOB handles for redirects")

4 years agonntp: handle 2-digit year "70" properly
Eric Wong [Wed, 1 Jan 2020 03:28:22 +0000 (03:28 +0000)]
nntp: handle 2-digit year "70" properly

Time::Local has the concept of a "rolling century" which is
defined at 50 years on either side of the current year.  Since
it's now 2020 and >50 years since the Unix epoch, the year "70"
gets interpreted by Time::Local as 2070-01-01 instead of
1970-01-01.

Since NNTP servers are unlikely to store messages from the
future, we'll feed 4-digit year to Time::Local::{timegm,timelocal}
and hopefully not have to worry about things until Y10K.

This fixes test failures on t/v2writable.t and t/nntpd.t since
2020-01-01.

4 years agospawn: better error handling
Eric Wong [Mon, 30 Dec 2019 05:04:16 +0000 (05:04 +0000)]
spawn: better error handling

Since vfork always shares memory between the child and parent,
we can propagate errors to the parent errno using shared memory
instead of just dumping to stderr and hoping somebody sees it.

4 years agospawn: support chdir via -C option
Eric Wong [Mon, 30 Dec 2019 05:04:15 +0000 (05:04 +0000)]
spawn: support chdir via -C option

This simplifies our admin module a bit and allows solver to be
used with v1 inboxes using git versions prior to v1.8.5 (but
still >= git v1.8.0).

4 years agospawn: allow passing GLOB handles for redirects
Eric Wong [Sun, 29 Dec 2019 12:51:18 +0000 (12:51 +0000)]
spawn: allow passing GLOB handles for redirects

We can save callers the trouble of {-hold} and {-dev_null}
refs as well as the trouble of calling fileno().

4 years agosearch: load_xapian: return true on success
Eric Wong [Sun, 29 Dec 2019 12:49:55 +0000 (12:49 +0000)]
search: load_xapian: return true on success

This was causing -xcpdb and other admin modules to fail
outside of tests (or when testing with the slow TEST_RUN_MODE=0).

4 years agoMerge branch 'no-closure'
Eric Wong [Sat, 28 Dec 2019 21:43:17 +0000 (21:43 +0000)]
Merge branch 'no-closure'

* no-closure: (30 commits)
  search: retry_reopen passes user arg to callback
  solvergit: allow passing arg to user-supplied callback
  viewvcs: avoid anonymous sub for HTML response
  wwwattach: avoid anonymous sub for msg_iter
  view: msg_iter calls add_body_text directly
  searchview: remove anonymous sub when sorting threads by relevance
  view: thread_html: pass named sub to WwwStream
  searchview: pass named subs to Www*Stream
  wwwtext: avoid anonymous sub in response
  contentid: no anonymous sub
  view: msg_html: stop using an anonymous sub
  view: avoid anon sub in stream_thread
  config: each_inbox: pass user arg to callback
  feed: avoid anonymous subs
  mboxgz: pass $ctx to callback to avoid anon subs
  www: lazy load Plack::Util
  githttpbackend: split out wwwstatic
  qspawn: psgi_return: allow non-anon parse_hdr callback
  qspawn: drop "qspawn.filter" support, for now
  qspawn: psgi_qx: eliminate anonymous subs
  ...

4 years agods: use MSG_MORE when wbuf is empty during long responses
Eric Wong [Sat, 28 Dec 2019 20:55:16 +0000 (20:55 +0000)]
ds: use MSG_MORE when wbuf is empty during long responses

HTTP::getline_pull and NNTP::long_step will both populate {wbuf}
manually to avoid recursion, so we need to account for an
empty-but-present {wbuf} while dispatching msg_more().

4 years agosearch: retry_reopen passes user arg to callback
Eric Wong [Wed, 25 Dec 2019 07:51:04 +0000 (07:51 +0000)]
search: retry_reopen passes user arg to callback

This allows callers to pass named (not anonymous) subs.

Update all retry_reopen callers to use this feature, and
fix some places where we failed to use retry_reopen :x

4 years agosolvergit: allow passing arg to user-supplied callback
Eric Wong [Wed, 25 Dec 2019 07:51:03 +0000 (07:51 +0000)]
solvergit: allow passing arg to user-supplied callback

This allows us to get rid of the requirement to capture
on-stack variables with an anonymous sub, as illustrated
with the update to viewvcs to take advantage of this.

v2: fix error handling for missing OIDs

4 years agoviewvcs: avoid anonymous sub for HTML response
Eric Wong [Wed, 25 Dec 2019 07:51:02 +0000 (07:51 +0000)]
viewvcs: avoid anonymous sub for HTML response

No need to create a new sub for every HTML page we render
with our VCS viewer.

4 years agowwwattach: avoid anonymous sub for msg_iter
Eric Wong [Wed, 25 Dec 2019 07:51:01 +0000 (07:51 +0000)]
wwwattach: avoid anonymous sub for msg_iter

We can pass arguments to msg_iter for msg_iter to pass
to our user-supplied callback, now.

4 years agoview: msg_iter calls add_body_text directly
Eric Wong [Wed, 25 Dec 2019 07:51:00 +0000 (07:51 +0000)]
view: msg_iter calls add_body_text directly

No need to waste several kilobytes creating an anonymous sub for
every invocation of msg_iter.

4 years agosearchview: remove anonymous sub when sorting threads by relevance
Eric Wong [Wed, 25 Dec 2019 07:50:59 +0000 (07:50 +0000)]
searchview: remove anonymous sub when sorting threads by relevance

We don't need to return a closure or have a separate hash
for sorting threads by relevance.  Instead, we can stuff
the relevance {pct} into the SearchMsg object itself and
use that.

Note: upon reviewing this code, the sort-by-relevance seems
bogus as it only considers the relevance of the topmost message.
Instead, it would make more sense to the user to sort by the
highest relevance of all messages in that particular thread.

4 years agoview: thread_html: pass named sub to WwwStream
Eric Wong [Wed, 25 Dec 2019 07:50:58 +0000 (07:50 +0000)]
view: thread_html: pass named sub to WwwStream

We can pass everything we need into the WWW $ctx to avoid
allocating kilobytes of memory for an anonymous sub for every
$MESSAGE_ID/t/ request.

4 years agosearchview: pass named subs to Www*Stream
Eric Wong [Wed, 25 Dec 2019 07:50:57 +0000 (07:50 +0000)]
searchview: pass named subs to Www*Stream

Both WwwStream and WwwAtomStream ->response pass the WWW $ctx
to the callback nowadays, so we can pass named subs to them.

4 years agowwwtext: avoid anonymous sub in response
Eric Wong [Wed, 25 Dec 2019 07:50:56 +0000 (07:50 +0000)]
wwwtext: avoid anonymous sub in response

We can pass arbitrary local variables via WWW $ctx, so
just pass that into the one-off _do_linkify sub which
already exists.

4 years agocontentid: no anonymous sub
Eric Wong [Wed, 25 Dec 2019 07:50:55 +0000 (07:50 +0000)]
contentid: no anonymous sub

msg_iter now passes a user specified arg into the supplied
callback, so we can use that to pass the Digest object into
the \&content_dig_i callback.

4 years agoview: msg_html: stop using an anonymous sub
Eric Wong [Wed, 25 Dec 2019 07:50:54 +0000 (07:50 +0000)]
view: msg_html: stop using an anonymous sub

Stash 5 local variables into the WWW $ctx hash table instead of
allocating several kilobytes for an anonymous sub.

4 years agoview: avoid anon sub in stream_thread
Eric Wong [Wed, 25 Dec 2019 07:50:53 +0000 (07:50 +0000)]
view: avoid anon sub in stream_thread

WwwStream already passes the WWW $ctx to the callback sub, so we
don't need to create a new sub every call to capture local variables
for the callback.

4 years agoconfig: each_inbox: pass user arg to callback
Eric Wong [Wed, 25 Dec 2019 07:50:52 +0000 (07:50 +0000)]
config: each_inbox: pass user arg to callback

Another place where we can replace anonymous subs with named
subs by passing a user-supplied arg.

4 years agofeed: avoid anonymous subs
Eric Wong [Wed, 25 Dec 2019 07:50:51 +0000 (07:50 +0000)]
feed: avoid anonymous subs

WwwStream already passes the WWW $ctx to the user-supplied
callback, and it's a trivial change for WwwAtomStream to do
the same.  Callers in Feed.pm can now take advantage of that
to save a few kilobytes of memory on every response.

4 years agomboxgz: pass $ctx to callback to avoid anon subs
Eric Wong [Wed, 25 Dec 2019 07:50:50 +0000 (07:50 +0000)]
mboxgz: pass $ctx to callback to avoid anon subs

Another place where we can rid ourselves of most anonymous subs
by passing the $ctx arg to the callback.

4 years agowww: lazy load Plack::Util
Eric Wong [Wed, 25 Dec 2019 07:50:49 +0000 (07:50 +0000)]
www: lazy load Plack::Util

cgit users won't need Plack::Util, here.

4 years agogithttpbackend: split out wwwstatic
Eric Wong [Wed, 25 Dec 2019 07:50:48 +0000 (07:50 +0000)]
githttpbackend: split out wwwstatic

Make it easier to share code between our GitHTTPBackend and Cgit
packages, for now, and possibly other packages in the future.

We can avoid inline_object and anonymous subs at the same
time, reducing per-request memory overhead.

4 years agoqspawn: psgi_return: allow non-anon parse_hdr callback
Eric Wong [Wed, 25 Dec 2019 07:50:47 +0000 (07:50 +0000)]
qspawn: psgi_return: allow non-anon parse_hdr callback

Callers can supply an arg to parse_hdr, now, eliminating the
need for closures to capture local variables.

4 years agoqspawn: drop "qspawn.filter" support, for now
Eric Wong [Wed, 25 Dec 2019 07:50:46 +0000 (07:50 +0000)]
qspawn: drop "qspawn.filter" support, for now

This feature was added in preparation for future changes
that have yet to materialize after nearly 3 years.  We
can re-add it if needed in the future.

4 years agoqspawn: psgi_qx: eliminate anonymous subs
Eric Wong [Wed, 25 Dec 2019 07:50:45 +0000 (07:50 +0000)]
qspawn: psgi_qx: eliminate anonymous subs

We can follow what we did in psgi_return to make psgi_qx
allocate less memory on each call.

4 years agoqspawn: psgi_return_start: hoist out from psgi_return
Eric Wong [Wed, 25 Dec 2019 07:50:44 +0000 (07:50 +0000)]
qspawn: psgi_return_start: hoist out from psgi_return

Instead of just passing the rpipe to the start_cb, pass the
entire qspawn ref to start_cb.  Update existing callers to
avoid circular refs.

4 years agoqspawn: psgi_return: initial cb can be named
Eric Wong [Wed, 25 Dec 2019 07:50:43 +0000 (07:50 +0000)]
qspawn: psgi_return: initial cb can be named

We can take advantage of HTTPD::Async being able to pass
user-supplied args to callbacks to get rid of one (of many)
anonymous subs in the code path.

4 years agohttpd/async: get rid of ephemeral main_cb
Eric Wong [Wed, 25 Dec 2019 07:50:42 +0000 (07:50 +0000)]
httpd/async: get rid of ephemeral main_cb

Cheaper to use up two hash table slots than creating a new sub.

4 years agoqspawn: reduce local vars, de-anonymize rd_hdr
Eric Wong [Wed, 25 Dec 2019 07:50:41 +0000 (07:50 +0000)]
qspawn: reduce local vars, de-anonymize rd_hdr

rd_hdr() now becomes a named subroutine instead of a per-call
local variable, so kilobytes of memory will not have to be
allocated for it on every ->psgi_return call.

4 years agomsg_iter: provide means to stop using anonymous subs
Eric Wong [Wed, 25 Dec 2019 07:50:40 +0000 (07:50 +0000)]
msg_iter: provide means to stop using anonymous subs

And remove the last anonymous sub in SolverGit itself.

4 years agoqspawn: replace anonymous $end callbacks w/ event_step
Eric Wong [Wed, 25 Dec 2019 07:50:39 +0000 (07:50 +0000)]
qspawn: replace anonymous $end callbacks w/ event_step

This will tie into the DS event loop if that's used, but
event_step an be called directly without relying on the
event loop from Apache or other HTTP servers (or PSGI tests).

4 years agoqspawn: disambiguate command vs PSGI env
Eric Wong [Wed, 25 Dec 2019 07:50:38 +0000 (07:50 +0000)]
qspawn: disambiguate command vs PSGI env

Make things easier-to-follow and paves the way for future work
to reduce dependencies on anonymous subs capturing local variables.

4 years agoqspawn: remove some anonymous subs for psgi_qx
Eric Wong [Wed, 25 Dec 2019 07:50:37 +0000 (07:50 +0000)]
qspawn: remove some anonymous subs for psgi_qx

By passing a user-supplied arg to $qx_cb, we can eliminate the
callers' need to capture on-stack variables with a closure.
This saves several kilobytes of memory allocation at the expense
of some extra hash table lookups in user-supplied callbacks.  It
also reduces the risk of memory leaks by eliminating a common
source of circular references.

4 years agohttpd/async: support passing arg to callbacks
Eric Wong [Wed, 25 Dec 2019 07:50:36 +0000 (07:50 +0000)]
httpd/async: support passing arg to callbacks

Another step towards removing anonymous subs to eliminate
a possible source of memory leaks and high memory use.

4 years agogit: allow async_cat to pass arg to callback
Eric Wong [Wed, 25 Dec 2019 07:50:35 +0000 (07:50 +0000)]
git: allow async_cat to pass arg to callback

This allows callers to avoid allocating several KB for for every
call to ->async_cat.

4 years agowwwlisting: do not rely on $? after ProcessPipe::CLOSE
Eric Wong [Thu, 26 Dec 2019 10:47:12 +0000 (10:47 +0000)]
wwwlisting: do not rely on $? after ProcessPipe::CLOSE

ProcessPipe::CLOSE won't reliably set $? inside the event loop
if waitpid(..., WNOHANG) isn't successful.  So use a blocking
waitpid() call, here, and hope "git show-ref" exits promptly
since we've already drained its stdout.

4 years agot/solver_git: test with -httpd, too
Eric Wong [Thu, 26 Dec 2019 06:48:04 +0000 (06:48 +0000)]
t/solver_git: test with -httpd, too

Solver uses the internal -httpd async API if available for
fairness when applying large patchsets.  We must test those
code paths in addition to the generic PSGI code paths.

4 years agot/www_listing: test "all" HTML listing
Eric Wong [Thu, 26 Dec 2019 06:48:03 +0000 (06:48 +0000)]
t/www_listing: test "all" HTML listing

We now have coverage for PublicInbox::WwwListing::list_all.

4 years agot/www_listing: quiet down stderr in -httpd
Eric Wong [Thu, 26 Dec 2019 06:48:02 +0000 (06:48 +0000)]
t/www_listing: quiet down stderr in -httpd

We need to init all.git for the v2 repo test to ensure
`git --git-dir=v2/all.git rev-parse --git-path objects/info/alternates`
doesn't warn or fail and clutter stderr.  This is noticeable
when setting TAIL="tail -F" in env before running this test.

4 years agot/psgi_v2: test search results Atom feed endpoint
Eric Wong [Wed, 25 Dec 2019 06:19:47 +0000 (06:19 +0000)]
t/psgi_v2: test search results Atom feed endpoint

The "x=A" search results endpoint finally gets test coverage.

4 years agot/search.t: update permissions check for OpenBSD
Eric Wong [Sun, 22 Dec 2019 22:17:40 +0000 (22:17 +0000)]
t/search.t: update permissions check for OpenBSD

OpenBSD (tested 6.5 on amd64) seems to follow the same semantics
as FreeBSD for S_ISGID, even if config.mak.uname in git.git
doesn't say so.

4 years agosearch: support SWIG-generated Xapian.pm
Eric Wong [Sun, 22 Dec 2019 22:17:39 +0000 (22:17 +0000)]
search: support SWIG-generated Xapian.pm

Xapian upstream is slowly phasing out the XS-based Search::Xapian
in favor of the SWIG-generated "Xapian" package.  While Debian and
both FreeBSD have Search::Xapian, OpenBSD only includes the "Xapian"
binding.

More information about the status of the "Xapian" Perl module here:
https://trac.xapian.org/ticket/523

4 years agosearchidx: call "++" on PostingIterator instead of "->inc"
Eric Wong [Sun, 22 Dec 2019 22:17:38 +0000 (22:17 +0000)]
searchidx: call "++" on PostingIterator instead of "->inc"

The "++" is not yet available in the SWIG-based "Xapian.pm" Perl
bindings, so use "++" where it's supported in both the XS
(Search::Xapian) and SWIG-based Xapian binding.

4 years agotestcommon: add require_mods method and use it
Eric Wong [Sun, 22 Dec 2019 22:17:37 +0000 (22:17 +0000)]
testcommon: add require_mods method and use it

This cuts down on lines of code in individual test cases and
fixes some misnamed error messages by using "$0" consistently.

This will also provide us with a method of swapping out
dependencies which provide equivalent functionality (e.g
"Xapian" SWIG can replace "Search::Xapian" XS bindings).

4 years agoremove "no warnings 'once'" in a few places
Eric Wong [Mon, 23 Dec 2019 23:06:03 +0000 (23:06 +0000)]
remove "no warnings 'once'" in a few places

We can use "use" to get the namespace into the "BEGIN" phase of
the interpreter.  While we're at it, use \&coderef syntax
explicitly instead of globbing everything.

4 years agonntp: cmd_xover: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:07 +0000 (08:00 +0000)]
nntp: cmd_xover: use named sub for long_response

Introduce xover_i, which does the same thing as the anonymous
sub it replaces.

4 years agonntp: hdr_msg_id: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:06 +0000 (08:00 +0000)]
nntp: hdr_msg_id: use named sub for long_response

Introduce hdr_msgid_range_i, which does the same thing as the
anonymous sub it replaces.

4 years agonntp: cmd_newnews: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:05 +0000 (08:00 +0000)]
nntp: cmd_newnews: use named sub for long_response

Introduce newnews_i, which does the same thing as the anonymous
sub it replaces.

4 years agonntp: cmd_listgroup: use named subs for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:04 +0000 (08:00 +0000)]
nntp: cmd_listgroup: use named subs for long_response

Introduce listgroup_range_i and listgroup_all_i subs which
do the same things as the anonymous subs they replace.

4 years agonntp: cmd_xrover: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:03 +0000 (08:00 +0000)]
nntp: cmd_xrover: use named sub for long_response

Introduce xrover_i which does the same thing as the anonymous
sub it replaces.

4 years agonntp: hdr_searchmsg: use named sub for numeric range response
Eric Wong [Sat, 21 Dec 2019 08:00:02 +0000 (08:00 +0000)]
nntp: hdr_searchmsg: use named sub for numeric range response

Introduce searchmsg_range_i, which does the same thing as
the anonymous sub it replaces.