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] git: fix unused code path for cat-file stderr reset
Date: Fri, 29 Sep 2023 10:41:05 +0000	[thread overview]
Message-ID: <20230929104105.2422700-1-e@80x24.org> (raw)

We haven't used _bidi_pipe idempotently in a while, so
the stderr was never getting reset on reads.
This isn't fully useful when using async eeeae20893a25956
(imap: use git-cat-file asynchronously, 2020-06-10)

So instead of truncating it on reads, we'll truncate
immediately after reading and rely on O_APPEND to keep
new writes at the end.

Fortunately, this stderrr error checking isn't used
outside of solver (which is synchronous).
---
 lib/PublicInbox/Git.pm | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 53887e3d..eb88aa48 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -136,24 +136,20 @@ sub object_format {
 
 sub last_check_err {
 	my ($self) = @_;
-	my $fh = $self->{err_c} or return;
-	sysseek($fh, 0, 0) or $self->fail("sysseek failed: $!");
-	defined(sysread($fh, my $buf, -s $fh)) or
-			$self->fail("sysread failed: $!");
+	my $fh = $self->{err_c} or return '';
+	sysseek($fh, 0, 0) or $self->fail("sysseek: $!");
+	my $size = -s $fh or return '';
+	sysread($fh, my $buf, $size) // $self->fail("sysread: $!");
+	truncate($fh, 0) or $self->fail("truncate: $!");
 	$buf;
 }
 
 sub _bidi_pipe {
 	my ($self, $batch, $in, $out, $pid, $err) = @_;
-	if ($self->{$pid}) {
-		if (defined $err) { # "err_c"
-			my $fh = $self->{$err};
-			sysseek($fh, 0, 0) or $self->fail("sysseek failed: $!");
-			truncate($fh, 0) or $self->fail("truncate failed: $!");
-		}
+	if (defined $self->{$pid}) {
+		Carp::cluck("BUG: self->{$pid} exists unexpectedly");
 		return;
 	}
-
 	pipe(my ($out_r, $out_w)) or $self->fail("pipe failed: $!");
 	my $rdr = { 0 => $out_r, pgid => 0 };
 	my $gd = $self->{git_dir};
@@ -169,9 +165,8 @@ sub _bidi_pipe {
 			'cat-file', "--$batch");
 	if ($err) {
 		my $id = "git.$self->{git_dir}.$batch.err";
-		my $fh = tmpfile($id) or $self->fail("tmpfile($id): $!");
-		$self->{$err} = $fh;
-		$rdr->{2} = $fh;
+		$self->{$err} = $rdr->{2} = tmpfile($id, undef, 1) or
+						$self->fail("tmpfile($id): $!");
 	}
 	# see lib/PublicInbox/ProcessPipe.pm for why we don't use that here
 	my ($in_r, $p) = popen_rd(\@cmd, undef, $rdr);

                 reply	other threads:[~2023-09-29 10:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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: http://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=20230929104105.2422700-1-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).