lib/PublicInbox/CmdIPC4.pm
lib/PublicInbox/CodeSearch.pm
lib/PublicInbox/CodeSearchIdx.pm
+lib/PublicInbox/Compat.pm
lib/PublicInbox/CompressNoop.pm
lib/PublicInbox/Config.pm
lib/PublicInbox/ConfigIter.pm
use PublicInbox::CidxLogP;
use PublicInbox::CidxComm;
use PublicInbox::Git qw(%OFMT2HEXLEN);
+use PublicInbox::Compat qw(uniqstr);
use Socket qw(MSG_EOR);
use Carp ();
our (
}
push @$dirs, @cur;
}
- my %uniq; # List::Util::uniq requires Perl 5.26+
- @$dirs = grep { !$uniq{$_}++ } @$dirs;
+ @$dirs = uniqstr @$dirs;
}
# SIG handlers:
$_ =~ /$re/ ? (push(@excl, $_), 0) : 1;
} @{$self->{git_dirs}};
warn("# excluding $_\n") for @excl;
- my %uniq; # List::Util::uniq requires Perl 5.26+
- @GIT_DIR_GONE = grep { !$uniq{$_}++ } (@GIT_DIR_GONE, @excl);
+ @GIT_DIR_GONE = uniqstr @GIT_DIR_GONE, @excl;
}
local $NCHANGE = 0;
local $LIVE_JOBS = $self->{-opt}->{jobs} ||
--- /dev/null
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# compatibility code for old Perl and standard modules, mainly
+# List::Util but maybe other stuff
+package PublicInbox::Compat;
+use v5.12;
+use parent qw(Exporter);
+require List::Util;
+
+our @EXPORT_OK = qw(uniqstr);
+
+# uniqstr is in List::Util 1.45+, which means Perl 5.26+;
+# so maybe 2030 for us since we need to support enterprise distros.
+# We can use uniqstr everywhere in our codebase and don't need
+# to account for special cases of `uniqnum' nor `uniq' in List::Util
+# even if they make more sense in some contexts
+no warnings 'once';
+*uniqstr = List::Util->can('uniqstr') // sub (@) {
+ my %seen;
+ grep { !$seen{$_}++ } @_;
+};
+
+1;
use PublicInbox::Eml;
use List::Util qw(max);
use Carp qw(croak);
+use PublicInbox::Compat qw(uniqstr);
# returns true if further checking is required
sub check_inodes ($) {
# nntp://news.example.com/alt.example
push @m, $u;
}
-
- # List::Util::uniq requires Perl 5.26+, maybe we
- # can use it by 2030 or so
- my %seen;
- @urls = grep { !$seen{$_}++ } (@urls, @m);
+ @urls = uniqstr @urls, @m;
}
\@urls;
}
@urls = map { m!\Apop3?s?://! ? $_ : "pop3://$_" } @$ps;
if (my $mi = $self->{'pop3mirror'}) {
my @m = map { m!\Apop3?s?://! ? $_ : "pop3://$_" } @$mi;
- my %seen; # List::Util::uniq requires Perl 5.26+
- @urls = grep { !$seen{$_}++ } (@urls, @m);
+ @urls = uniqstr @urls, @m;
}
my $n = 0;
for (@urls) { $n += s!/+\z!! }
use v5.10.1;
use parent qw(PublicInbox::IPC PublicInbox::LeiInput);
use PublicInbox::InboxWritable qw(eml_from_path);
+use PublicInbox::Compat qw(uniqstr);
# /^input_/ subs are used by (or override) PublicInbox::LeiInput superclass
my @oidbin = $lms ? $lms->name_oidbin($folder, $bn) : ();
@oidbin > 1 and warn("W: $folder/*/$$bn not unique:\n",
map { "\t".unpack('H*', $_)."\n" } @oidbin);
- my %seen;
- my @docids = sort { $a <=> $b } grep { !$seen{$_}++ }
+ my @docids = sort { $a <=> $b } uniqstr
map { $lse->over->oidbin_exists($_) } @oidbin;
my $vmd = $self->{-import_kw} ? { kw => $kw } : undef;
if (scalar @docids) {
use strict;
use v5.10.1;
use parent qw(PublicInbox::IPC);
+use PublicInbox::Compat qw(uniqstr);
sub new {
my ($cls, $lei) = @_;
my $uid_url = "$url/;UID=$uid";
@oidbin > 1 and warn("W: $uid_url not unique:\n",
map { "\t".unpack('H*', $_)."\n" } @oidbin);
- my %seen;
- my @docids = sort { $a <=> $b } grep { !$seen{$_}++ }
+ my @docids = sort { $a <=> $b } uniqstr
map { $self->{over}->oidbin_exists($_) } @oidbin;
$self->{lse}->kw_changed(undef, $kw, \@docids) or return;
$self->{verbose} and $self->{lei}->qerr("# $uid_url => @$kw\n");
use strict;
use v5.10.1;
use parent qw(PublicInbox::Lock);
+use PublicInbox::Compat qw(uniqstr);
use DBI qw(:sql_types); # SQL_BLOB
use PublicInbox::ContentHash qw(git_sha);
use Carp ();
--all=@no not accepted (must be `local' and/or `remote')
EOM
}
- my (%seen, @inc);
my @all = $self->folders;
for my $ok (@ok) {
if ($ok eq 'local') {
- @inc = grep(!m!\A[a-z0-9\+]+://!i, @all);
+ push @$folders, grep(!m!\A[a-z0-9\+]+://!i, @all);
} elsif ($ok eq 'remote') {
- @inc = grep(m!\A[a-z0-9\+]+://!i, @all);
+ push @$folders, grep(m!\A[a-z0-9\+]+://!i, @all);
} elsif ($ok ne '') {
return $lei->fail("--all=$all not understood");
} else {
- @inc = @all;
+ push @$folders, @all;
}
- push(@$folders, (grep { !$seen{$_}++ } @inc));
}
+ @$folders = uniqstr @$folders;
scalar(@$folders) || $lei->fail(<<EOM);
no --mail-sync folders known to lei
EOM
SELECT oidbin FROM blob2num WHERE fid = ? AND uid = ? ORDER BY _rowid_
EOM
$sth->execute($fid, $uid);
- my %uniq; # for public-inbox <= 1.7.0
- grep { !$uniq{$_}++ } map { $_->[0] } @{$sth->fetchall_arrayref};
+ # for public-inbox <= 1.7.0:
+ uniqstr(map { $_->[0] } @{$sth->fetchall_arrayref});
}
sub name_oidbin ($$$) {
$sth->bind_param(2, $nm, SQL_VARCHAR);
$sth->execute;
my @old = map { $_->[0] } @{$sth->fetchall_arrayref};
- my %uniq; # for public-inbox <= 1.7.0
- grep { !$uniq{$_}++ } (@bin, @old);
+ uniqstr @bin, @old # for public-inbox <= 1.7.0
}
sub imap_oidhex {
use PublicInbox::Tmpfile;
use PublicInbox::GitAsyncCat;
use PublicInbox::Eml;
+use PublicInbox::Compat qw(uniqstr);
use URI::Escape qw(uri_escape_utf8);
# POSIX requires _POSIX_ARG_MAX >= 4096, and xargs is required to
my $diffs = delete $self->{tmp_diffs};
if (scalar @$diffs) {
unshift @{$self->{patches}}, @$diffs;
- my %seen; # List::Util::uniq requires Perl 5.26+ :<
- my @u = grep { !$seen{$_}++ } map { di_url($self, $_) } @$diffs;
+ my @u = uniqstr(map { di_url($self, $_) } @$diffs);
dbg($self, "found $want->{oid_b} in " . join(" ||\n\t", @u));
++$self->{nr_p};