From: Eric Sunshine <sunshine@sunshineco.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Pratik Karki <predatoramigo@gmail.com>, Git List <git@vger.kernel.org>
Subject: Re: [GSoC] [PATCH] test: avoid pipes in git related commands for test suite
Date: Wed, 14 Mar 2018 14:22:45 -0400 [thread overview]
Message-ID: <CAPig+cTLCswg_=q5ybnyN3As4Au05q5eAcA7Prr643KCgZ0OAw@mail.gmail.com> (raw)
In-Reply-To: <87zi3bdlo2.fsf@evledraar.gmail.com>
On Wed, Mar 14, 2018 at 5:57 AM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Wed, Mar 14 2018, Eric Sunshine jotted:
>> On Tue, Mar 13, 2018 at 4:19 PM, Pratik Karki <predatoramigo@gmail.com> wrote:
>>> - 'git diff-tree -r -M --name-status HEAD^ HEAD | \
>>> - grep "^R100..*path0/COPYING..*path2/COPYING" &&
>>> - git diff-tree -r -M --name-status HEAD^ HEAD | \
>>> - grep "^R100..*path0/README..*path2/README"'
>>> + 'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
>>> + grep "^R100..*path0/COPYING..*path2/COPYING" actual &&
>>> + git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
>>> + grep "^R100..*path0/README..*path2/README" actual'
>>
>> Although this "mechanical" transformation is technically correct, it
>> is nevertheless wasteful. The exact same "git diff-tree ..." command
>> is run twice, and both times output is captured to file 'actual',
>> which makes the second invocation superfluous. Instead, a better
>> transformation would be:
>>
>> git diff-tree ... >actual &&
>> grep ... actual &&
>> grep ... actual
>>
> I think we have to be careful to not be overly picky with rejecting
> mechanical transformations that fix bugs on the basis that while we're
> at it the test could also be rewritten.
>
> I.e. this bug was there before, maybe we should purely focus on just
> replacing the harmful pipe pattern that hides errors in this series and
> leave rewriting the actual test logic for a later patch.
Thanks for presenting an opposing opinion. While I understand your
position, the reason for my suggested transformation is that if the
patch already transformed the code in the way suggested, it would
increase my confidence, as a reviewer, that the patch author had
_studied_ and _understood_ the code. Increased confidence is
especially important for mechanical transformations since -- as seen
in the unsnipped review comment below -- blindly-applied mechanical
transformations can be suboptimal or outright incorrect.
It's also the sort of review comment I would make even to very
seasoned project participants[1].
[1]: https://public-inbox.org/git/CAPig+cQLmYQeRhPxvZHmY7gApnbE25H_KoSWs-ZjuBo4BruimQ@mail.gmail.com/
>>> - test $(git cat-file commit refs/remotes/glob | \
>>> - grep "^parent " | wc -l) -eq 2
>>> + test $(git cat-file commit refs/remotes/glob >actual &&
>>> + grep "^parent " actual | wc -l) -eq 2
>>
>> This is not a great transformation. If "git cat-file" fails, then
>> neither 'grep' nor 'wc' will run, and the result will be as if 'test'
>> was called without an argument before "-eq". For example:
>>
>> % test $(false >actual && grep "^parent " actual | wc -l) -eq 2
>> test: -eq: unary operator expected
>>
>> It would be better to run "git cat-file" outside of "test $(...)". For instance:
>>
>> git cat-file ... >actual &&
>> test $(grep ... actual | wc -l) -eq 2
>>
>> Alternately, you could take advantage of the test_line_count() helper function:
>>
>> git cat-file ... >actual &&
>> grep ... actual >actual2 &&
>> test_line_count = 2 actual2
>
> In this case though as you rightly point out the rewrite is introducing
> a regression, which should definitely be fixed.
next prev parent reply other threads:[~2018-03-14 18:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-13 20:19 [GSoC] [PATCH] test: avoid pipes in git related commands for test suite Pratik Karki
2018-03-14 7:30 ` Eric Sunshine
2018-03-14 9:57 ` Ævar Arnfjörð Bjarmason
2018-03-14 18:22 ` Eric Sunshine [this message]
2018-03-15 17:04 ` Junio C Hamano
2018-03-19 17:32 ` [GSoC][PATCH] " Pratik Karki
2018-03-21 11:02 ` Eric Sunshine
2018-03-21 15:23 ` [GSoC][PATCH v3] test: avoid pipes in git related commands for test Pratik Karki
2018-03-21 18:11 ` Junio C Hamano
2018-03-21 18:45 ` Eric Sunshine
2018-03-21 18:58 ` Eric Sunshine
2018-03-23 15:01 ` [GSoC][PATCH v4] " Pratik Karki
2018-03-25 8:37 ` Eric Sunshine
2018-03-27 17:31 ` [GSoC][PATCH v5] " Pratik Karki
2018-03-30 21:45 ` Eric Sunshine
2018-03-30 22:08 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPig+cTLCswg_=q5ybnyN3As4Au05q5eAcA7Prr643KCgZ0OAw@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=predatoramigo@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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).