git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/2] revision: allow --ancestry-path to take an argument

From
Derrick Stolee <derrickstolee@github.com>
Date
Aug 18, 2022, 16:51 UTC
Message-ID
<59b3af21-0685-1819-38bc-8afd826bee6f@github.com>
In-Reply-To
<220818.86ilmp8rzn.gmgdl@evledraar.gmail.com>
On 8/18/2022 11:50 AM, Ævar Arnfjörð Bjarmason wrote:
Show 35 quoted lines
> 
> On Thu, Aug 18 2022, Derrick Stolee wrote:
> 
>> On 8/18/2022 2:17 AM, Elijah Newren via GitGitGadget wrote:
>>> +test_expect_success 'rev-list --ancestry-path=F D..M' '
>>> +	test_write_lines E F J L M >expect &&
>>> +	git rev-list --ancestry-path=F --format=%s D..M |
>>> +	sed -e "/^commit /d" |
>>> +	sort >actual &&
>>> +	test_cmp expect actual
>>> +'
>>
>> These tests follow the patterns from other tests in this file, but
>> it also has bad patterns. Specifically, the 'git rev-list' command
>> is fed directly into a pipe. I include a patch below that applies
>> directly on this one to rewrite these tests. If you want, you could
>> rebase to have that test refactor happen before you add your new
>> --ancestry-path=<X> option tests.
> 
> Thanks, I was going to comment on the same, but your solution is much
> better (I was just going to suggest using intermediate files).
> 
>> [...]
>> -test_expect_success 'rev-list --ancestry-path D..M -- M.t' '
>> -	echo M >expect &&
>> -	git rev-list --ancestry-path --format=%s D..M -- M.t |
>> -	sed -e "/^commit /d" >actual &&
>> -	test_cmp expect actual
>> -'
>> +test_ancestry () {
>> +	args=$1
>> +	expected=$2
> 
> Maybe add &&-chaining here (we do it in some cases, but I'm not sure
> when such assignments would ever fail).
These are outside of a test_expect_success, so they are not important.
 
Show 11 quoted lines
>> +	test_expect_success "rev-list $args" "
>> +		test_write_lines $expected >expect &&
>> +		git rev-list --format=%s $args >raw &&
>> +
>> +		if test -n \"$expected\"
> 
> Aren't you making things harder for yourself here than required by using
> ""-quoting for the body of the test.
> 
> We eval it into existence, so you can use ''-quotes, and then you don't
> need to escape e.g. the "" quotes here for expected, no?

Are "args" and "expected" in-scope if I use single quotes? I don't think they are unless we export them. I could be wrong.

Show 6 quoted lines
>> +		then
>> +			sed -e \"/^commit /d\" raw | sort >actual &&
> 
> nit for debuggability (and not correctness), maybe using intermediate
> files here would be nicer? And then perhaps call them "actual" and
> "actual.sorted".

I don't think that level of debuggability is important. We have the raw file if we want to see what the Git output was.

Show 6 quoted lines
> 
>> +			test_cmp expect actual || return 1
> 
> No need for a "return 1" here when we're not in a loop. It's redundant,
> and makes the -x output on failure confusing ("why didn't I fail on the
> test_cmp, but on this stray return?...").

Sure. I did this more out of habit, but it makes sense that we don't need it for an if block.

Show 9 quoted lines
> ...
> 
>> +		else
>> +			test_must_be_empty raw
> 
> ...which would also allow you to extract much of this if/else at the
> cost of not using test_must_be_empty, i.e. just make the "expected"
> empty unless "$expected" is provided. Just a thought/nit, we could also
> leave this as-is :)
*shrug* either way is fine by me.
> Also does the "compare rev" part of this want test_cmp_rev instead?

I don't know what you mean here. We are not comparing revisions anywhere, but we are using the commit messages to create an easy comparison for the output.

Thanks, -Stolee

Previous: Ævar Arnfjörð BjarmasonNext: Eric Sunshine
Message 11 of 29 in “Allow --ancestry-path to take an argument”
  1. 0/2 Allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 17, 2022
  2. 1/2 rev-list-options.txt: fix simple typoElijah Newren via GitGitGadget, Aug 17, 2022
  3. 2/2 revision: allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 17, 2022
  4. Junio C HamanoAug 17, 2022
  5. Elijah NewrenAug 18, 2022
  6. 0/2 Allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 18, 2022
  7. 1/2 rev-list-options.txt: fix simple typoElijah Newren via GitGitGadget, Aug 18, 2022
  8. 2/2 revision: allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 18, 2022
  9. Derrick StoleeAug 18, 2022
  10. Ævar Arnfjörð BjarmasonAug 18, 2022
  11. Derrick StoleeAug 18, 2022
  12. Eric SunshineAug 18, 2022
  13. Elijah NewrenAug 19, 2022
  14. Ævar Arnfjörð BjarmasonAug 19, 2022
  15. Eric SunshineAug 18, 2022
  16. Elijah NewrenAug 19, 2022
  17. Jonathan TanAug 18, 2022
  18. Elijah NewrenAug 19, 2022
  19. Jonathan TanAug 19, 2022
  20. Junio C HamanoAug 18, 2022
  21. 0/3 Allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 19, 2022
  22. 1/3 rev-list-options.txt: fix simple typoElijah Newren via GitGitGadget, Aug 19, 2022
  23. 2/3 t6019: modernize tests with helperDerrick Stolee via GitGitGadget, Aug 19, 2022
  24. 3/3 revision: allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 19, 2022
  25. Junio C HamanoAug 19, 2022
  26. Elijah NewrenAug 20, 2022
  27. Derrick StoleeAug 19, 2022
  28. Junio C HamanoAug 19, 2022
  29. Elijah NewrenAug 20, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.