From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Emily Shaffer <emilyshaffer@google.com>, git@vger.kernel.org
Subject: Re: [PATCH 1/2] gc: add tests for --cruft and friends
Date: Thu, 04 Aug 2022 09:09:53 -0700 [thread overview]
Message-ID: <xmqqtu6s6lda.fsf@gitster.g> (raw)
In-Reply-To: <220804.86a68ke9d5.gmgdl@evledraar.gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Thu, 04 Aug 2022 09:48:24 +0200")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>> +test_expect_success 'gc --cruft generates a cruft pack' '
>> + git init crufts &&
>> + test_when_finished "rm -fr crufts" &&
>
> Let's "test_when_finished" first, then "git init", the point is to clean
> up the directory if we fail.
Good advice.
We say "rm -fr" not "rm -r" there because we do not want to see a
failure to remove if "git init" failed before it manages to create
the directory ;-)
>
>> + (
>> + cd crufts &&
>> + test_commit base &&
>> +
>> + test_commit --no-tag foo &&
>> + test_commit --no-tag bar &&
>> + git reset HEAD^^ &&
>> +
>> + git gc --cruft &&
>> +
>> + cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
>> + test_path_is_file .git/objects/pack/$cruft.pack
>> + )
>> +'
>
> ...this...
>
>> +test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
>> + git init crufts &&
>> + test_when_finished "rm -fr crufts" &&
>> + (
>> + cd crufts &&
>> + test_commit base &&
>> +
>> + test_commit --no-tag foo &&
>> + test_commit --no-tag bar &&
>> + git reset HEAD^^ &&
>> +
>> + git -c gc.cruftPacks=true gc &&
>> +
>> + cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
>> + test_path_is_file .git/objects/pack/$cruft.pack
>> + )
>> +'
>> +
>
> ...whole thing seems to be copy/pasted aside from the git options.
>
> If so let's factor this into a trivial helper that invokes git "$@",
> then call it with "gc --cruft" and "-c ..."?
With shell, passing "here is a series of commands to be run in the
middle of a boilerplate sequence" is indeed easy to write, but it
gets harder to follow and quote correctly, which is why I'd rather
not see that pattern overused.
A pair of helper functions, one of which prepares a sample history
to be used, and the other checks if we created one (or more) cruft
packs, may achieve the same conciseness while remaining to be more
readable. I.e.
test_when_finished "rm -fr crufts" &&
git init crufts &&
(
cd crufts &&
prepare_history &&
git -c gc.cruftPacks=true gc &&
cruft_packs_exist
)
perhaps?
next prev parent reply other threads:[~2022-08-04 16:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 20:57 [PATCH 0/2] let feature.experimental imply gc.cruftPacks=true Emily Shaffer
2022-08-03 20:57 ` [PATCH 1/2] gc: add tests for --cruft and friends Emily Shaffer
2022-08-03 21:56 ` Junio C Hamano
2022-08-04 7:48 ` Ævar Arnfjörð Bjarmason
2022-08-04 16:09 ` Junio C Hamano [this message]
2022-08-03 20:57 ` [PATCH 2/2] config: let feature.experimental imply gc.cruftPacks=true Emily Shaffer
2022-08-03 22:05 ` Junio C Hamano
2022-08-04 13:05 ` Derrick Stolee
2022-08-04 16:10 ` 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=xmqqtu6s6lda.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=emilyshaffer@google.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).