From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/5] git: cat_async_step: reduce batch-command info checks
Date: Wed, 12 Apr 2023 00:12:58 +0000 [thread overview]
Message-ID: <20230412001302.685421-2-e@80x24.org> (raw)
In-Reply-To: <20230412001302.685421-1-e@80x24.org>
This improves readability for me. Instead of checking for `info '
requests of `--batch-command' in multiple places of every
common branch, do it once per-call and stash its result.
We'll also avoid storing `$bc' for now since the only other
check is in a cold path.
---
lib/PublicInbox/Git.pm | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index f153237b..cc337e5d 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -262,20 +262,19 @@ sub cat_async_step ($$) {
my $head = my_readline($self->{in}, $rbuf);
my $cmd = ref($req) ? $$req : $req;
# ->fail may be called via Gcf2Client.pm
- my $bc = $self->{-bc};
+ my $info = $self->{-bc} && substr($cmd, 0, 5) eq 'info ';
if ($head =~ /^([0-9a-f]{40,}) (\S+) ([0-9]+)$/) {
($oid, $type, $size) = ($1, $2, $3 + 0);
- unless ($bc && $cmd =~ /\Ainfo /) { # --batch-command
+ unless ($info) { # --batch-command
$bref = my_read($self->{in}, $rbuf, $size + 1) or
$self->fail(defined($bref) ?
'read EOF' : "read: $!");
chop($$bref) eq "\n" or
$self->fail('LF missing after blob');
}
- } elsif ($bc && $cmd =~ /\Ainfo / &&
- $head =~ / (missing|ambiguous)\n/) {
+ } elsif ($info && $head =~ / (missing|ambiguous)\n/) {
$type = $1;
- $oid = substr($cmd, 5);
+ $oid = substr($cmd, 5); # remove 'info '
} elsif ($head =~ s/ missing\n//s) {
$oid = $head;
# ref($req) indicates it's already been retried
@@ -286,7 +285,7 @@ sub cat_async_step ($$) {
$type = 'missing';
if ($oid eq '') {
$oid = $cmd;
- $oid =~ s/\A(?:contents|info) // if $bc;
+ $oid =~ s/\A(?:contents|info) // if $self->{-bc};
}
} else {
my $err = $! ? " ($!)" : '';
@@ -294,7 +293,7 @@ sub cat_async_step ($$) {
}
$self->{rbuf} = $rbuf if $$rbuf ne '';
splice(@$inflight, 0, 3); # don't retry $cb on ->fail
- if ($bc && $cmd =~ /\Ainfo /) {
+ if ($info) {
eval { $cb->($oid, $type, $size, $arg, $self) };
async_err($self, $req, $oid, $@, 'check') if $@;
} else {
next prev parent reply other threads:[~2023-04-12 0:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-12 0:12 [PATCH 0/5] various cleanups and tweaks Eric Wong
2023-04-12 0:12 ` Eric Wong [this message]
2023-04-12 0:12 ` [PATCH 2/5] gzip_filter: use carp in ->bail for failure checks Eric Wong
2023-04-12 0:13 ` [PATCH 3/5] git: rename version() to git_version() Eric Wong
2023-04-12 0:13 ` [PATCH 4/5] www_coderepo: drop unused $EACH_REF variable Eric Wong
2023-04-12 0:13 ` [PATCH 5/5] git: parallelize manifest_entry 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=20230412001302.685421-2-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.
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).