From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 6/6] switch git version comparisons to vstrings, too
Date: Fri, 7 Apr 2023 12:40:53 +0000 [thread overview]
Message-ID: <20230407124053.2233988-7-e@80x24.org> (raw)
In-Reply-To: <20230407124053.2233988-1-e@80x24.org>
There's too many require_git callsites in t/*.t to change,
but we can make the rest of the code more readable and reuse
PublicInbox::Git::version() in our test suite, too.
---
lib/PublicInbox/Git.pm | 11 +++++------
lib/PublicInbox/LeiMirror.pm | 2 +-
lib/PublicInbox/TestCommon.pm | 16 ++++++----------
3 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 6f8232cf..e35d5277 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -33,7 +33,7 @@ our $async_warn; # true in read-only daemons
# 65: SHA-256 hex size + "\n" in preparation for git using non-SHA1
use constant {
MAX_INFLIGHT => 512 * 3 / (65 + length('contents ')),
- BATCH_CMD_VER => (2 << 24 | 36 << 16), # git 2.36+
+ BATCH_CMD_VER => v2.36.0, # git 2.36+
};
my %GIT_ESC = (
@@ -67,8 +67,7 @@ sub check_git_exe () {
close($rd) or die "$GIT_EXE --version: $?";
$v =~ /\b([0-9]+(?:\.[0-9]+){2})/ or die
"$GIT_EXE --version output: $v # unparseable";
- my @v = split(/\./, $1, 3);
- $GIT_VER = ($v[0] << 24) | ($v[1] << 16) | $v[2];
+ $GIT_VER = eval("v$1") // die "BUG: bad vstring: $1 ($v)";
$EXE_ST = $st;
}
}
@@ -159,7 +158,7 @@ sub _bidi_pipe {
# git 2.31.0+ supports -c core.abbrev=no, don't bother with
# core.abbrev=64 since not many releases had SHA-256 prior to 2.31
- my $abbr = $GIT_VER < (2 << 24 | 31 << 16) ? 40 : 'no';
+ my $abbr = $GIT_VER lt v2.31.0 ? 40 : 'no';
my @cmd = ($GIT_EXE, "--git-dir=$gd", '-c', "core.abbrev=$abbr",
'cat-file', "--$batch");
if ($err) {
@@ -316,7 +315,7 @@ sub cat_async_wait ($) {
sub batch_prepare ($) {
my ($self) = @_;
check_git_exe();
- if ($GIT_VER >= BATCH_CMD_VER) {
+ if ($GIT_VER ge BATCH_CMD_VER) {
_bidi_pipe($self, qw(batch-command in out pid err_c));
$self->{-bc} = 1;
} else {
@@ -370,7 +369,7 @@ sub check_async_begin ($) {
die 'BUG: already in async check' if $self->{inflight_c};
cleanup($self) if alternates_changed($self);
check_git_exe();
- if ($GIT_VER >= BATCH_CMD_VER) {
+ if ($GIT_VER ge BATCH_CMD_VER) {
_bidi_pipe($self, qw(batch-command in out pid err_c));
$self->{-bc} = 1;
$self->{inflight} = [];
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index e0709fbd..8f749688 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -276,7 +276,7 @@ sub fetch_args ($$) {
($lei->{opt}->{jobs} // 1) > 1;
push @cmd, '-v' if $lei->{opt}->{verbose};
push(@cmd, '-p') if $lei->{opt}->{prune};
- PublicInbox::Git::version() >= ((2 << 24) | (29 << 16)) and
+ PublicInbox::Git::version() ge v2.29.0 and
push(@cmd, '--no-write-fetch-head');
@cmd;
}
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 494323c0..aa2abc43 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -10,6 +10,7 @@ use Fcntl qw(F_SETFD :seek);
use POSIX qw(dup2);
use IO::Socket::INET;
use File::Spec;
+use Scalar::Util qw(isvstring);
our @EXPORT;
my $lei_loud = $ENV{TEST_LEI_ERR_LOUD};
my $tail_cmd = $ENV{TAIL};
@@ -109,17 +110,12 @@ sub have_xapian_compact (;$) {
sub require_git ($;$) {
my ($req, $nr) = @_;
- state ($cur_int, $cur_ver);
- $cur_int //= do {
- chomp($cur_ver = xqx([qw(git --version)]));
- my @v = ($cur_ver =~ /version (\d+)\.(\d+)(?:\.(\d+))?/);
- ($v[0] << 24) | ($v[1] << 16) | ($v[2] // 0);
- };
-
- my ($req_maj, $req_min, $req_sub) = split(/\./, $req);
- my $req_int = ($req_maj << 24) | ($req_min << 16) | ($req_sub // 0);
+ require PublicInbox::Git;
+ state $cur_vstr = PublicInbox::Git::version();
+ $req = eval("v$req") unless isvstring($req);
- return 1 if $cur_int >= $req_int;
+ return 1 if $cur_vstr ge $req;
+ state $cur_ver = sprintf('%vd', $cur_vstr);
return plan skip_all => "git $req+ required, have $cur_ver" if !$nr;
defined(wantarray) ? undef :
skip("git $req+ required (have $cur_ver), skipping $nr tests")
prev parent reply other threads:[~2023-04-07 12:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 12:40 [PATCH 0/6] cindex fixes, and some spring cleaning Eric Wong
2023-04-07 12:40 ` [PATCH 1/6] cindex: improve progress display Eric Wong
2023-04-07 12:40 ` [PATCH 2/6] cindex: preserve indexlevel across invocations Eric Wong
2023-04-07 12:40 ` [PATCH 3/6] umask: hoist out of InboxWritable Eric Wong
2023-04-07 12:40 ` [PATCH 4/6] umask: rely on the OnDestroy-based call where applicable Eric Wong
2023-04-07 12:40 ` [PATCH 5/6] searchidx: use vstring to improve readability Eric Wong
2023-04-07 12:40 ` Eric Wong [this message]
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=20230407124053.2233988-7-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).