]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
4 years agoviewdiff: add "b=" param with non-standard diff prefix
Eric Wong [Sat, 25 Jan 2020 04:45:07 +0000 (04:45 +0000)]
viewdiff: add "b=" param with non-standard diff prefix

<20180228012207.GB251290@aiede.svl.corp.google.com> (posted to
git@vger) uses "i" and "w" prefixes instead of the standard "a"
and "b" prefixes, ensure we emit a "b=$FILENAME" param for the
solver endpoint to improve search accuracy, syntax highlighting,
and information density in the URL itself.

4 years agosearchidx: don't assume "a/" and "b/" as prefixes
Eric Wong [Sat, 25 Jan 2020 04:45:06 +0000 (04:45 +0000)]
searchidx: don't assume "a/" and "b/" as prefixes

Some people use "--{src,dst}-prefix=", try to deal with those
since git-apply can handle them when called by solver.

4 years agosearchidx: skip filenames on "diff --git ..."
Eric Wong [Sat, 25 Jan 2020 04:45:05 +0000 (04:45 +0000)]
searchidx: skip filenames on "diff --git ..."

We already capture filenames on the lines beginning
with "---" and "+++", so it's redundant work to capture
filenames from "diff --git ..." lines.

4 years agolinkify: move to_html over from ViewDiff
Eric Wong [Sat, 25 Jan 2020 04:45:04 +0000 (04:45 +0000)]
linkify: move to_html over from ViewDiff

We use the same idiom in many places for doing two-step
linkification and HTML escaping.  Get rid of an outdated
comment in flush_quote while we're at it.

4 years agolinkify: compile $LINK_RE once
Eric Wong [Sat, 25 Jan 2020 04:45:03 +0000 (04:45 +0000)]
linkify: compile $LINK_RE once

This gives a 3-4% performance improvement in xt/perf-msgview.t
with a mirror of https://public-inbox.org/meta/

4 years agoview: inline and eliminate msg_html
Eric Wong [Sat, 25 Jan 2020 04:45:02 +0000 (04:45 +0000)]
view: inline and eliminate msg_html

No need to keep the old sub around, anymore.  Rename auxiliary
subs to "msg_page_*" instead of the "html" version.

4 years agoxt/perf-msgview: switch to multipart_text_as_html
Eric Wong [Sat, 25 Jan 2020 04:45:01 +0000 (04:45 +0000)]
xt/perf-msgview: switch to multipart_text_as_html

It's a more widely-used (but still internal) API which will
probably last longer than msg_html.  It also reaches deeper into
the stack and avoids the overhead of ->getline via PSGI, so it's
faster and gives a more accurate measurement of lower-level parts.

4 years agotests: move the majority of t/view.t into t/plack.t
Eric Wong [Sat, 25 Jan 2020 04:45:00 +0000 (04:45 +0000)]
tests: move the majority of t/view.t into t/plack.t

And some more into t/mid.t.  PublicInbox::View::msg_html may
change internally, so lets rely on the stable PSGI interface
to test it, rather than a test which reaches deep into the
internals.

4 years agoinit: use Import::run_die instead of system()
Eric Wong [Sat, 25 Jan 2020 04:44:59 +0000 (04:44 +0000)]
init: use Import::run_die instead of system()

We already load PublicInbox::Import via
PublicInbox::InboxWritable, so it's not an extra module
to load.  This can give us a slight speedup in tests.

4 years agot/plack.t: modernize and unindent
Eric Wong [Sat, 25 Jan 2020 04:44:58 +0000 (04:44 +0000)]
t/plack.t: modernize and unindent

This test will be expanded, and we can take advantage of
run_script to simplify our internal API use.

4 years agoview: start performing buffering into {obuf}
Eric Wong [Sat, 25 Jan 2020 04:44:57 +0000 (04:44 +0000)]
view: start performing buffering into {obuf}

Get rid of the confusingly named {rv} and {tip} fields
and unify them into {obuf} for readability.

{obuf} usage may be expanded to more areas in the future.  This
will eventually make it easier for us to experiment with
alternative buffering schemes.

4 years agowwwstream: discard single-use $ctx fields after use
Eric Wong [Sat, 25 Jan 2020 04:44:56 +0000 (04:44 +0000)]
wwwstream: discard single-use $ctx fields after use

This should make it clear that we only use these elements
once and can discard them.  While we're in the area, avoid
escaping '"' by using qq() instead of "" to quote strings
requiring interpolation.

4 years agoview: simplify duplicate Message-ID handling
Eric Wong [Sat, 25 Jan 2020 04:44:55 +0000 (04:44 +0000)]
view: simplify duplicate Message-ID handling

It's an uncommon code path, no need to make it more complex
than it needs to be by having extra sub parameters.

4 years agoview: thread_skel: drop constant tpfx parameter
Eric Wong [Sat, 25 Jan 2020 04:44:54 +0000 (04:44 +0000)]
view: thread_skel: drop constant tpfx parameter

It hasn't changed in a few years.  Now we can rely on constant
folding to avoid extraneous ops to the $skel buffer.

4 years agoview: reduce parameters for html_footer
Eric Wong [Sat, 25 Jan 2020 04:44:53 +0000 (04:44 +0000)]
view: reduce parameters for html_footer

Put more logic into html_footer and less in its only caller so
we can control the buffering and string creation.

4 years agosearchview: keep $noop sub private to the package
Eric Wong [Sat, 25 Jan 2020 04:44:52 +0000 (04:44 +0000)]
searchview: keep $noop sub private to the package

It'll always be used as a callback, so there's no point in
giving it a name to be called non-anonymously.  Making
assigments to it is slightly faster since there's no need
to repeatedly do a lookup by name.

4 years agoview: improve readability around walk_thread
Eric Wong [Sat, 25 Jan 2020 04:44:51 +0000 (04:44 +0000)]
view: improve readability around walk_thread

Pass \&coderefs explicitly to walk_thread, and add some
prototypes + comments to describe what goes on.

4 years agowww: use "skel" terminology consistently
Eric Wong [Sat, 25 Jan 2020 04:44:50 +0000 (04:44 +0000)]
www: use "skel" terminology consistently

This saves us a few comments and confusion.   Yes, it's a
destination so "dst" can be appropriate, but we may be using
that term elsewhere.

4 years agowww*stream: favor \&close instead of *close
Eric Wong [Sat, 25 Jan 2020 04:44:49 +0000 (04:44 +0000)]
www*stream: favor \&close instead of *close

Be explicit that we're making a code reference, and not
a reference to a scalar, array, hash, or IO...

4 years agoxapcmd: increase scope of lock
Eric Wong [Sun, 26 Jan 2020 01:17:44 +0000 (01:17 +0000)]
xapcmd: increase scope of lock

The old lock scope was only sufficient for protecting against
concurrent modifications from the common -mda, -watch, or -learn
writers.

It was not sufficient for protecting against parallel -compact
or -xcpdb invocations from eager admins.  Most of the time this
only leads to confusing and misleading warning messages, but
parallel xcpdb --reshard could lead to errors.

4 years agosearch: {version} => {ibx_ver}
Eric Wong [Sun, 26 Jan 2020 01:17:43 +0000 (01:17 +0000)]
search: {version} => {ibx_ver}

We don't confuse human readers with the Xapian schema version.
We also want to make it obvious this is the version of the inbox
we're indexing, these are Search or SearchIdx objects, not Inbox
objects.

4 years agoinbox: add ->version method
Eric Wong [Sun, 26 Jan 2020 01:17:42 +0000 (01:17 +0000)]
inbox: add ->version method

This allows us to simplify version checking by avoiding
"//" or "||" operators sprinkled around.

4 years agoswitch to sysseek + sysread for serving static files
Eric Wong [Sat, 25 Jan 2020 20:57:57 +0000 (20:57 +0000)]
switch to sysseek + sysread for serving static files

The "perlio" layer doesn't do read(2) syscalls over 8192 bytes
at the moment, and binmode($fh, ':unix') leaks[1].  So use
sysseek and sysread for now, since I can't see retaining
compatibility with PerlIO::scalar being worth the trouble.

[1] http://nntp.perl.org/group/perl.perl5.porters/256918

4 years agos/news.gmane.org/news.gmane.io/
Eric Wong [Sat, 25 Jan 2020 08:59:58 +0000 (08:59 +0000)]
s/news.gmane.org/news.gmane.io/

gmane still has a NNTP server, so update links to point to it.

cf. https://lars.ingebrigtsen.no/2020/01/06/whatever-happened-to-news-gmane-org/

4 years agowwwstatic: wire up buffer bypass for -httpd
Eric Wong [Fri, 24 Jan 2020 09:43:52 +0000 (09:43 +0000)]
wwwstatic: wire up buffer bypass for -httpd

This prevents public-inbox-httpd from buffering ->getline
results from a static file into another temporary file when
writing to slow clients.  Instead we inject the static file
ref with offsets and length directly into the {wbuf} queue.

It took me a while to decide to go this route, some
rejected ideas:

1. Using Plack::Util::set_io_path and having PublicInbox::HTTP
   serve the result directly.  This is compatible with what
   some other PSGI servers do using sendfile.  However, neither
   Starman or Twiggy currently use sendfile for partial responses.

2. Parsing the Content-Range response header for offsets and
   lengths to use with set_io_path for partial responses.

These rejected ideas required increasing the complexity of HTTP
response writing in PublicInbox::HTTP in the common, non-static
file cases.  Instead, we made minor changes to the colder write
buffering path of PublicInbox::DS and leave the hot paths
untouched.

We still support generic PSGI servers via ->getline.  However,
since we don't know the characteristics of other PSGI servers,
we no longer do a 64K initial read in an attempt to negotiate a
larger TCP window.

4 years agods: tmpio: store offsets per-buffer
Eric Wong [Fri, 24 Jan 2020 09:43:51 +0000 (09:43 +0000)]
ds: tmpio: store offsets per-buffer

We want to be able to inject existing file handles + offsets and
even lengths into this in the future, without going through the
->getline interface[1]

We also switch to using a 64K buffer size since we can safely
discard whatever got truncated on write and full writes can help
negotiate a larger TCP window for high-latency, high-bandwidth
links.

While we're at it, make it obvious that we're using O_APPEND for
our tmpfile() interface so we can seek freely for reading while
the writer always prints to the end of the file.

[1] the getline interface for serving static files may result
    in us buffering on-FS data into another temporary file,
    which is a waste.

4 years agowwwstatic: offload error handling to PSGI server
Eric Wong [Fri, 24 Jan 2020 09:43:50 +0000 (09:43 +0000)]
wwwstatic: offload error handling to PSGI server

The PSGI server needs to account for ->getline failing
due to disk failures or truncated files, anyways.  So
just die() ourselves and let the PSGI server log and
drop the client.

4 years agohttp: eliminate short-lived cyclic ref for psgix.io
Eric Wong [Fri, 24 Jan 2020 09:43:49 +0000 (09:43 +0000)]
http: eliminate short-lived cyclic ref for psgix.io

While there is no known actual leak due to reference cycles,
here, eliminating a potential source of leaks is helpful.

4 years agospelling: favor `publicly' over `publically'
Eric Wong [Fri, 24 Jan 2020 22:09:33 +0000 (22:09 +0000)]
spelling: favor `publicly' over `publically'

While both can be correct, the former seems more common,
is shorter, and is also consistent with the spelling found
in the AGPL-3.0 text.

4 years agowebsite: omit technical/ and other subdirs
Eric Wong [Fri, 24 Jan 2020 22:09:32 +0000 (22:09 +0000)]
website: omit technical/ and other subdirs

We don't need to clutter the website with unnecessary technical
information.  Anybody who reads the technical/ directory should
be looking at our source code, anyways; and we also have cgit
and gitweb mirrors.

4 years agodoc: INSTALL describe required deps for released versions
Eric Wong [Fri, 24 Jan 2020 22:09:31 +0000 (22:09 +0000)]
doc: INSTALL describe required deps for released versions

1.3.0 isn't out, yet, and sometimes folks will rely on
INSTALL on our website while installing older versions,
so try to clarify that.

4 years agowebsite: re-add top-level files
Eric Wong [Fri, 24 Jan 2020 22:09:30 +0000 (22:09 +0000)]
website: re-add top-level files

I noticed the TODO was out-of-date on the website, among some
other things.  This was broken in moving GNU-isms in the
Makefile to Perl.

4 years agodoc: avoid needless rebuilds of NEWS
Eric Wong [Fri, 24 Jan 2020 22:09:29 +0000 (22:09 +0000)]
doc: avoid needless rebuilds of NEWS

Repeatedly rebuilding `NEWS' because the mtime of `NEWS'
is synched to the latest release .eml is a bit annoying,
but necessary to save bandwidth for the website.

So we'll also update the mtime of the source .eml file when
reading them.  It's kinda gross to be setting mtimes of source
.eml files in Documentation/RelNotes/, but I can't think of
anything better at the moment...

4 years agombox: handle empty subjects after dropping "Re:" prefix
Eric Wong [Sat, 25 Jan 2020 02:47:08 +0000 (02:47 +0000)]
mbox: handle empty subjects after dropping "Re:" prefix

We can't pass empty strings to `to_filename' without
triggering warnings, and `to_filename' on an empty string
makes no sense.

4 years agocontentid: ignore duplicate References: headers
Eric Wong [Thu, 23 Jan 2020 23:05:59 +0000 (23:05 +0000)]
contentid: ignore duplicate References: headers

OverIdx::parse_references already skips duplicate
References (which we use in SearchThread for rendering).
So there's no reason for our content deduplication logic
to care if a Message-Id in the Reference header is mentioned
twice.

4 years agowwwstream: shorten cloneurl uniquification
Eric Wong [Thu, 23 Jan 2020 23:05:58 +0000 (23:05 +0000)]
wwwstream: shorten cloneurl uniquification

Another place where List::Scalar::uniq doesn't make sense,
but there's a small op reduction to be had anyways.

4 years agomid: shorten uniq_mids logic
Eric Wong [Thu, 23 Jan 2020 23:05:57 +0000 (23:05 +0000)]
mid: shorten uniq_mids logic

We won't be able to use List::Util::uniq here, but we can still
shorten our logic and make it more consistent with the rest of
our code which does similar things.

4 years agoinbox: simplify filtering for duplicate NNTP URLs
Eric Wong [Thu, 23 Jan 2020 23:05:56 +0000 (23:05 +0000)]
inbox: simplify filtering for duplicate NNTP URLs

And add a note to remind ourselves to use List::Util::uniq
when it becomes common.

4 years agonntp: simplify setting X-Alt-Message-ID
Eric Wong [Thu, 23 Jan 2020 23:05:55 +0000 (23:05 +0000)]
nntp: simplify setting X-Alt-Message-ID

We can cut down on the number of operations required
using "grep" instead of "foreach".

4 years agocontentid: use map to generate %seen for Message-Ids
Eric Wong [Thu, 23 Jan 2020 23:05:54 +0000 (23:05 +0000)]
contentid: use map to generate %seen for Message-Ids

This use of map {} is a common idiom as we no longer consider
the Message-ID as part of the digest.

4 years agohval: from_attr: move to unit test
Eric Wong [Sun, 19 Jan 2020 09:40:52 +0000 (09:40 +0000)]
hval: from_attr: move to unit test

We don't call from_attr anywhere outside of tests, so don't
bloat normal processes with it.

4 years agohval: to_attr: support wide characters
Eric Wong [Sun, 19 Jan 2020 09:40:51 +0000 (09:40 +0000)]
hval: to_attr: support wide characters

We need to escape wide characters when making attribute names from
filename-looking things in diffstats.

4 years agodoc: some 1.3.0 release notes updates
Eric Wong [Tue, 14 Jan 2020 07:56:26 +0000 (07:56 +0000)]
doc: some 1.3.0 release notes updates

4 years agosigfd: simplify loop and improve documentation
Eric Wong [Sun, 12 Jan 2020 21:17:56 +0000 (21:17 +0000)]
sigfd: simplify loop and improve documentation

We can use the return value of sysread to bound our loop instead
of repeatedly shortening the string.  Furthermore add some
comments which can be easily checked against the signalfd(2)
manpage.

4 years agods: flatten $EXPMAP, delete entries on close
Eric Wong [Sun, 12 Jan 2020 21:17:55 +0000 (21:17 +0000)]
ds: flatten $EXPMAP, delete entries on close

We can reduce the amount of small arrayrefs in memory
by flattening $EXPMAP.  This forces us to properly clean
up references during deferred close handling, so NNTP
(and soon HTTP) connections no longer linger until expiry.

4 years agods: rely on autovivification for $later_queue
Eric Wong [Sun, 12 Jan 2020 21:17:54 +0000 (21:17 +0000)]
ds: rely on autovivification for $later_queue

No reason to have an empty arrayref lying around when not
everybody needs it.

Re-indent the later-related subs since we're changing a
bunch of lines, anyways.

4 years agods: rely on autovivication for waitpid bits
Eric Wong [Sun, 12 Jan 2020 21:17:53 +0000 (21:17 +0000)]
ds: rely on autovivication for waitpid bits

No need to create an arrayref until we need it, and fix up a
comment while we're in the area.  Some aesthetic changes while
we're at it:

- Rename $WaitPids to $wait_pids to make it clear this is
  unique to our implementation and not in Danga::Socket.

- rewrite dwaitpid() to reduce indentation level

4 years agods: rely on autovivification for nextq
Eric Wong [Sun, 12 Jan 2020 21:17:52 +0000 (21:17 +0000)]
ds: rely on autovivification for nextq

Another place we can delay creating arrays until needed.

4 years agods|http|nntp: simplify {wbuf} population
Eric Wong [Sun, 12 Jan 2020 21:17:51 +0000 (21:17 +0000)]
ds|http|nntp: simplify {wbuf} population

We can rely on autovification to turn `undef' value of {wbuf}
into an arrayref.

Furthermore, "push" returns the (new) size of the array since at
least Perl 5.0 (I didn't look further back), so we can use that
return value instead of calling "scalar" again.

4 years agods: guard ToClose against DESTROY side-effects
Eric Wong [Sun, 12 Jan 2020 21:17:50 +0000 (21:17 +0000)]
ds: guard ToClose against DESTROY side-effects

This does not affect our current code, but theoretically a
DESTROY callback could call PublicInbox::DS::close to enqueue
elements into the ToClose array.  So take a similar strategy as
we do with other queues (e.g. $nextq) by swapping references to
arrays, rather than operating on the array itself.

Since close operations are relatively rare, we can rely on
auto-vivification via "push" ops to create the array on an
as-needed basis.

Since we're in the area, clean up the PostLoopCallback
invocation to use the ternary operator rather than a confusing
(to me) combination of statements.

Finally, add a prototype to strengthen compile-time checking,
and move it in front of our only caller to make use of
the prototype.

4 years agods: remove Timer->cancel and Timer class+bless
Eric Wong [Sun, 12 Jan 2020 21:17:49 +0000 (21:17 +0000)]
ds: remove Timer->cancel and Timer class+bless

It doesn't seem needed at the moment, and we can re-add it
in the future if needed.

4 years agods: add an in_loop() function for Inbox.pm use
Eric Wong [Sun, 12 Jan 2020 21:17:48 +0000 (21:17 +0000)]
ds: add an in_loop() function for Inbox.pm use

Inbox.pm accessing the $in_loop variable directly raises
warnings when Inbox is loaded without DS.

4 years agods: add_timer: rename from AddTimer, remove a parameter
Eric Wong [Sun, 12 Jan 2020 21:17:47 +0000 (21:17 +0000)]
ds: add_timer: rename from AddTimer, remove a parameter

The class parameter is pointless, especially for an internal
sub which only has one external caller in a test.  Add a sub
prototype while we're at it to get some compile time checking.

4 years agods: new: avoid redundant check, make clobbering fatal
Eric Wong [Sun, 12 Jan 2020 21:17:46 +0000 (21:17 +0000)]
ds: new: avoid redundant check, make clobbering fatal

"fileno(undef)" already dies under "use strict", so there's no
need to check for it ourselves.  As far as "fileno($closed_io)"
or "fileno($fake_io)" goes, we'll let epoll_ctl detect the
error, instead.

Our design should make DescriptorMap entries impossible to clobber,
so make it fatal via confess in case it does happen, because
inadvertantly clobbering a FD would be very bad.  While we're at
it, remove a redundant return statement and rely on implicit
returns.

4 years agouse popen_rd for bidirectional pipes
Eric Wong [Sat, 11 Jan 2020 22:35:03 +0000 (22:35 +0000)]
use popen_rd for bidirectional pipes

popen_rd accepts arbitrary redirects, so we can reuse its
code to setup the pipe end we want to read, saving each
caller a few lines of code compared to calling pipe+spawn.

4 years agot/solver_git: avoid uninitialized warnings in hostname generation
Eric Wong [Sat, 11 Jan 2020 22:35:02 +0000 (22:35 +0000)]
t/solver_git: avoid uninitialized warnings in hostname generation

Outside of tests, this is only relevant for non-PSGI use, which
may happen someday...

Fixes: cb1c874520153f5c ("inbox: use PublicInbox::Git::host_prefix_url for base_url")
4 years agoxt/git_async_cmp: do not slurp large OID list into memory
Eric Wong [Sat, 11 Jan 2020 22:35:01 +0000 (22:35 +0000)]
xt/git_async_cmp: do not slurp large OID list into memory

I somehow thought "foreach (<$cat>)" could work like
"while (<$cat>)" when it came to iterating over file
handles...

4 years agoxapcmd: use popen_rd for running xapian-compact
Eric Wong [Sat, 11 Jan 2020 22:35:00 +0000 (22:35 +0000)]
xapcmd: use popen_rd for running xapian-compact

public-inbox-compact wrapper displays progress by default,
anyways, and there's not a lot of output, so simplify our
code by using popen_rd instead of spawn + optional pipe.

While we're at it use "while (<HANDLE>)" to display
progress as it happens, since "foreach (<$HANDLE>)"
slurps the contents into an array, first.

4 years agocgit: drop cgit_parse_hdr wrapper
Eric Wong [Sat, 11 Jan 2020 22:34:59 +0000 (22:34 +0000)]
cgit: drop cgit_parse_hdr wrapper

Unlike PublicInbox::GitHTTPBackend::git_parse_hdr,
cgit_parse_hdr does nothing interesting besides calling
parse_cgi_headers.  So just make a reference to
PublicInbox::GitHTTPBackend::parse_cgi_headers and call it.

4 years agosolver: path_a may be undef from /dev/null
Eric Wong [Sat, 11 Jan 2020 22:34:58 +0000 (22:34 +0000)]
solver: path_a may be undef from /dev/null

This avoids uninitialized variable warnings when viewing
newly-created files.

4 years agogit: packed_bytes: use GLOB_NOSORT
Eric Wong [Sat, 11 Jan 2020 22:34:57 +0000 (22:34 +0000)]
git: packed_bytes: use GLOB_NOSORT

File::Glob is loaded by the perl for the "glob()" op, anyways,
so call bsd_glob with the GLOB_NOSORT to avoid needless sorting
of the output.

4 years agogit: modified: don't slurp `rev-parse --branches'
Eric Wong [Sat, 11 Jan 2020 22:34:56 +0000 (22:34 +0000)]
git: modified: don't slurp `rev-parse --branches'

While v1 inboxes typically only have one branch, code repositories
may have dozens or even hundreds.  Slurping those into memory is
a waste.

4 years agoconfig: do not slurp entire cgitrc at once
Eric Wong [Sat, 11 Jan 2020 22:34:55 +0000 (22:34 +0000)]
config: do not slurp entire cgitrc at once

cgitrc files can have hundreds or thousands of lines in them and
slurping them into memory is a waste.  "while (<$fh>)" only
reads one line at a time, whereas "for (<$fh>)" reads the entire
contents of the file into a temporary array.

4 years agoexamples/unsubscribe.milter: support unique mailto:
Eric Wong [Fri, 10 Jan 2020 22:55:30 +0000 (22:55 +0000)]
examples/unsubscribe.milter: support unique mailto:

Instead of providing a generic "mailto:foo+unsubscribe@example.com"
address in List-Unsubscribe which requires confirmation, replace it
with a mailto: header with a unique subject which contains the same
unique ID we put in the https:// URL.

This makes it easier for some MUAs without https:// support to
unsubscribe with a single action via the List-Unsubscribe header.

4 years agoexamples/unsubscribe.milter: skip gmane-mx
Eric Wong [Fri, 10 Jan 2020 22:55:29 +0000 (22:55 +0000)]
examples/unsubscribe.milter: skip gmane-mx

Mail to gmane is being delivered to gmane-mx.org, nowadays, and
we don't want ordinary readers to be able to trigger unconfirmed
unsubscription off any mailing lists which go through our
unsubscribe.milter.

https://lars.ingebrigtsen.no/2020/01/06/whatever-happened-to-news-gmane-org/

4 years agowww: discard multipart parent on iteration
Eric Wong [Sat, 11 Jan 2020 06:28:16 +0000 (06:28 +0000)]
www: discard multipart parent on iteration

We're often iterating through messages while writing to another
buffer in our WWW interface, causing memory usage to multiply.
Since we know we won't need to keep the MIME object around in
some cases, and can tell msg_iter to clobber the on-stack
variable while it operates on subparts of multipart messages.

With xt/mem-msgview.t switched to multipart from the previous
commit, this shows a 13 MB memory reduction on that test.

4 years agoxt/mem-msgview.t: change to test one multipart message
Eric Wong [Sat, 11 Jan 2020 06:28:15 +0000 (06:28 +0000)]
xt/mem-msgview.t: change to test one multipart message

A single multipart message is far more common than
a reused Message-ID, so rewrite the test to only have
a single multipart message.  Memory improvements will
be implemented in the next commit.

4 years agomake Filesys::Notify::Simple optional
Eric Wong [Fri, 10 Jan 2020 08:49:32 +0000 (08:49 +0000)]
make Filesys::Notify::Simple optional

It's only used by us in public-inbox-watch, and maybe not
for long.  It's in most installations because Plack pulls it
in though, but Plack is no longer required.

4 years agomake Plack optional for non-WWW and non-httpd users
Eric Wong [Fri, 10 Jan 2020 08:49:31 +0000 (08:49 +0000)]
make Plack optional for non-WWW and non-httpd users

Some users just want to run -mda, -watch, and/or -nntpd.
Let them run just those without forcing them to pull in a
bunch of dependencies.

4 years agodoc: technical/ds.txt: describe PublicInbox::DS divergences
Eric Wong [Fri, 10 Jan 2020 20:35:33 +0000 (20:35 +0000)]
doc: technical/ds.txt: describe PublicInbox::DS divergences

Danga::Socket 1.62 was released a few months back and
the maintainer indicated it would be the last release.
We've diverged significantly in incompatible ways...

While most of this should've already been documented in
commit messages, putting it all into one document could
make it easier-to-digest.

It's also a strange design for anybody used to conventional
event loops.  Maybe this is an unconventional project :P

4 years agospawn (and thus popen_rd) die on failure
Eric Wong [Fri, 10 Jan 2020 09:14:19 +0000 (09:14 +0000)]
spawn (and thus popen_rd) die on failure

Most spawn and popen_rd callers die on failure to spawn,
anyways, and some are missing checks entirely.  This saves
us a bunch of verbose error-checking code in callers.

This also makes popen_rd more consistent, since it already
dies on pipe creation failures.

4 years agogit: remove ->commit_title method
Eric Wong [Fri, 10 Jan 2020 09:14:18 +0000 (09:14 +0000)]
git: remove ->commit_title method

We haven't used it in SolverGit, yet, and I'll be reworking it
to work with ->cat_async, instead.

4 years agogit: ->modified uses cat_async
Eric Wong [Fri, 10 Jan 2020 09:14:17 +0000 (09:14 +0000)]
git: ->modified uses cat_async

While v1 inboxes are typically only a single branch, coderepos
will have many branches and being able to pipeline requests
to "git cat-file --batch" can help us mask seek times.

4 years agoallow HTTP_HOST to be '0' via defined() checks
Eric Wong [Fri, 10 Jan 2020 09:14:16 +0000 (09:14 +0000)]
allow HTTP_HOST to be '0' via defined() checks

'0' is a valid value for HTTP_HOST, and maybe some folks
will want to hit that as port 80 where the HTTP client won't
send the ":$PORT" suffix.

4 years agoinbox: use PublicInbox::Git::host_prefix_url for base_url
Eric Wong [Fri, 10 Jan 2020 09:14:15 +0000 (09:14 +0000)]
inbox: use PublicInbox::Git::host_prefix_url for base_url

Better not to duplicate the same logic across different classes.

Also, our git wrapper class is a strange place for
host_prefix_url, but it needs to be usable for coderepos, so
it's there, for now...

4 years agoqspawn: catch transient errors on pipe, EPOLL_CTL_ADD
Eric Wong [Thu, 9 Jan 2020 11:14:52 +0000 (11:14 +0000)]
qspawn: catch transient errors on pipe, EPOLL_CTL_ADD

popen_rd dies on pipe()/pipe2() failure due to FD exhaustion.

EPOLL_CTL_ADD (via PublicInbox::HTTPD::Async->new) may also fail
due to memory exhaustion or exceeding the value of
/proc/sys/fs/epoll/max_user_watches

4 years agohttp: log response_write errors
Eric Wong [Thu, 9 Jan 2020 11:14:51 +0000 (11:14 +0000)]
http: log response_write errors

Application-supplied callbacks may error out, try to log them
so the PSGI app developer can figure out what went wrong.

4 years agolistener: EPOLL_CTL_ADD errors are non fatal
Eric Wong [Thu, 9 Jan 2020 11:14:50 +0000 (11:14 +0000)]
listener: EPOLL_CTL_ADD errors are non fatal

EPOLL_CTL_ADD may fail with transient ENOMEM or ENOSPC errors,
so don't tear down the process when that happens.

4 years agonntp: correctly log long response errors
Eric Wong [Wed, 8 Jan 2020 10:44:09 +0000 (10:44 +0000)]
nntp: correctly log long response errors

We cannot safely call "fileno(undef)" without bringing down the
entire -nntpd process :x.  To ensure no logging regression, we
now stash the FD for the duration of the long response to ensure
the error can be matched to the original command in logs.

Fixes: 207b89615a1a0c06 ("nntp: remove cyclic refs from long_response")
4 years agodaemon: ignore SIGPIPE while running
Eric Wong [Wed, 8 Jan 2020 10:44:08 +0000 (10:44 +0000)]
daemon: ignore SIGPIPE while running

This is only needed for IO::Poll users, since users with
(signalfd || EVFILT_SIGNAL) support run with SIGPIPE (and
all other signals) blocked.

Fixes: 81a9a43fb858d197 ("daemon: use sigprocmask to block signals at startup")
4 years agosyscall: modernize away from pre-Perl-5.6 conventions
Eric Wong [Sun, 5 Jan 2020 23:23:36 +0000 (23:23 +0000)]
syscall: modernize away from pre-Perl-5.6 conventions

"use vars" was superseded by "our" in Perl 5.6, and we
can "use parent qw(Exporter)" in favor of manipulating
@ISA directly (or the bigger "use base ...");

While we're at it, avoid multiple invocations of constant->import
by passing a hashref as a "use" parameter.

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.