From: Junio C Hamano <gitster@pobox.com>
To: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/4] t: remove \{m,n\} from BRE grep usage
Date: Tue, 20 Sep 2022 10:52:20 -0700 [thread overview]
Message-ID: <xmqq35cm6ii3.fsf@gitster.g> (raw)
In-Reply-To: 752b12ef1e27d3b69d6aa3734309895082be7886.1663688697.git.congdanhqx@gmail.com
Đoàn Trần Công Danh <congdanhqx@gmail.com> writes:
> \{m,n\} is a GNU extension to BRE, and it's forbidden by our
> CodingGuidelines.
Is it?
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_06
says otherwise. There may be some other GNU extensions to BRE that
allows you to write ERE elements with different syntax, but I doubt
this is one of them. Perhaps you are thinking about "A\|B"
alternation? In ERE "A|B" is alternation, and GNU BRE allows "A\|B"
but that is outside POSIX, IIUC. "A\+" (1 or more of A) and "A\?"
(0 or 1 of A) are the same way.
We do say we don't use "\{m,n\}" in the guidelines, which was
written more than 10 years ago that codifies the habit acquired
while having to deal with regexp implementations of various UNIX
variants like early SystemV and BSD4 from more than 20 years ago.
If we are using the syntax in many of our tests that everybody runs,
that can be taken as a sign that those platforms who had problems
with the syntax have died out, or at least to them Git does not
matter.
So my prefererence is to
- Allow \{m,n\} when it makes sense and codify it in the guidelines
- Rewriting tests is fine if it makes the result easier to read,
but it shouldn't be done for the sole purpose of getting rid of
the \{m,n\} syntax.
- As there are folks without GNU, until these GNU extensions for |,
+, and ? are adopted widely, keep forbidding their use in BRE.
> test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
> msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
> - grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
> - grep "^0\{40\}.*$msg$" .git/logs/HEAD
> + zero="00000000" &&
> + zero="$zero$zero$zero$zero$zero" &&
> + grep " $zero.*$msg$" .git/logs/HEAD &&
> + grep "^$zero.*$msg$" .git/logs/HEAD
> '
This is not good
> test_expect_success 'git branch -M should leave orphaned HEAD alone' '
> diff --git a/t/t3305-notes-fanout.sh b/t/t3305-notes-fanout.sh
> index 22ffe5bcb9..aa3bb2e308 100755
> --- a/t/t3305-notes-fanout.sh
> +++ b/t/t3305-notes-fanout.sh
> @@ -9,7 +9,7 @@ path_has_fanout() {
> path=$1 &&
> fanout=$2 &&
> after_last_slash=$(($(test_oid hexsz) - $fanout * 2)) &&
> - echo $path | grep -q "^\([0-9a-f]\{2\}/\)\{$fanout\}[0-9a-f]\{$after_last_slash\}$"
> + echo $path | grep -q -E "^([0-9a-f][0-9a-f]/){$fanout}[0-9a-f]{$after_last_slash}$"
The use of -E makes it more readable and is good. The innermost "a
pair of hexdigits" that would repeat $fanout times may be easier to
read if you keep the {2}, though.
next prev parent reply other threads:[~2022-09-20 17:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 15:49 [PATCH 0/4] allow grep -E, and remove egrep Đoàn Trần Công Danh
2022-09-20 15:49 ` [PATCH 1/4] CodingGuidelines: allow grep -E Đoàn Trần Công Danh
2022-09-20 15:49 ` [PATCH 2/4] t: remove \{m,n\} from BRE grep usage Đoàn Trần Công Danh
2022-09-20 16:43 ` SZEDER Gábor
2022-09-20 17:42 ` Phillip Wood
2022-09-20 17:52 ` Junio C Hamano [this message]
2022-09-20 15:49 ` [PATCH 3/4] t: convert egrep usage to "grep -E" Đoàn Trần Công Danh
2022-09-20 15:49 ` [PATCH 4/4] t: convert fgrep usage to "grep -F" Đoàn Trần Công Danh
2022-09-20 17:52 ` [PATCH 0/4] allow grep -E, and remove egrep 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=xmqq35cm6ii3.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=congdanhqx@gmail.com \
--cc=git@vger.kernel.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 NNTP newsgroup(s).