From: Eric Sunshine <sunshine@sunshineco.com>
To: Denton Liu <liu.denton@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 5/7] Makefile: add 'check-sort' target
Date: Tue, 16 Mar 2021 02:37:16 -0400 [thread overview]
Message-ID: <CAPig+cRM2y15cH5gLvmn5dDa=rafBL53GPua8rmjsTsmkQAkPA@mail.gmail.com> (raw)
In-Reply-To: <5088e93d76e44de9d079b7b2296b8c810828a2f5.1615856156.git.liu.denton@gmail.com>
On Mon, Mar 15, 2021 at 8:57 PM Denton Liu <liu.denton@gmail.com> wrote:
> In the previous few commits, we sorted many lists into ASCII-order. In
> order to ensure that they remain that way, add the 'check-sort' target.
> [...]
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> +my @regexes = map { qr/^$_/ } @ARGV;
> +my $last_regex = 0;
> +my $last_line = '';
> +while (<STDIN>) {
> + my $matched = 0;
> + chomp;
> + for my $regex (@regexes) {
> + next unless $_ =~ $regex;
> + if ($last_regex == $regex) {
> + die "duplicate lines: '$_'\n" unless $last_line ne $_;
> + die "unsorted lines: '$last_line' before '$_'\n" unless $last_line lt $_;
> + }
> + $matched = 1;
> + $last_regex = $regex;
> + $last_line = $_;
> + }
> + unless ($matched) {
> + $last_regex = 0;
> + $last_line = '';
> + }
> +}
This is, of course, endlessly bikesheddable. Here is a shorter -- and,
at least for me, easier to understand -- way to do it:
my $rc = 0;
chomp(my @all = <STDIN>);
foreach my $needle (@ARGV) {
my @lines = grep(/^$needle/, @all);
if (join("\n", @lines) ne join("\n", sort @lines)) {
print "'$needle' lines not sorted\n";
$rc = 1;
}
}
exit $rc;
By the way, it might be a good idea to also print the filename in
which the problem occurred. Such context can be important for the
person trying to track down the complaint. To do so, you'd probably
want to pass the filename as an argument, and open and read the file
rather than sending it only as standard-input.
next prev parent reply other threads:[~2021-03-16 6:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 0:56 [PATCH 0/7] Sort lists and add static-analysis Denton Liu
2021-03-16 0:56 ` [PATCH 1/7] Makefile: mark 'check-builtins' as a .PHONY target Denton Liu
2021-03-16 4:59 ` Eric Sunshine
2021-03-17 17:47 ` Junio C Hamano
2021-03-16 0:56 ` [PATCH 2/7] Makefile: ASCII-sort LIB_OBJS Denton Liu
2021-03-16 0:56 ` [PATCH 3/7] builtin.h: ASCII-sort list of functions Denton Liu
2021-03-17 17:51 ` Junio C Hamano
2021-03-16 0:56 ` [PATCH 4/7] test-tool.h: " Denton Liu
2021-03-17 17:54 ` Junio C Hamano
2021-03-16 0:56 ` [PATCH 5/7] Makefile: add 'check-sort' target Denton Liu
2021-03-16 6:37 ` Eric Sunshine [this message]
2021-03-17 9:50 ` Denton Liu
2021-03-17 12:47 ` Ævar Arnfjörð Bjarmason
2021-03-17 17:32 ` Jeff King
2021-03-17 17:42 ` Ævar Arnfjörð Bjarmason
2021-03-17 21:48 ` Eric Sunshine
2021-03-17 22:01 ` Jeff King
2021-03-17 18:01 ` Junio C Hamano
2021-03-17 18:16 ` Ævar Arnfjörð Bjarmason
2021-03-17 17:59 ` Junio C Hamano
2021-03-16 0:56 ` [PATCH 6/7] ci/run-static-analysis.sh: make check-builtins Denton Liu
2021-03-16 0:56 ` [PATCH 7/7] ci/run-static-analysis.sh: make check-sort Denton Liu
2021-03-17 11:01 ` [PATCH 0/7] Sort lists and add static-analysis Bagas Sanjaya
2021-03-17 18:05 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPig+cRM2y15cH5gLvmn5dDa=rafBL53GPua8rmjsTsmkQAkPA@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=liu.denton@gmail.com \
/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 NNTP newsgroup(s).