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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 18, 2022 at 8:57 AM Ævar Arnfjörð Bjarmason
<avarab@xxxxxxxxx> wrote:
>
> 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).
>
> > +     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?
>
> > +             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".

Would be better to just nuke the sed by replacing 'rev-list' with
'log' (the line already has a --format option, so might as well get
the output we want).

> > +                     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?...").
>
> ...
>
> > +             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 :)
>
> Also does the "compare rev" part of this want test_cmp_rev instead?

Um, I don't see any "compare rev" part of this, or any revision
comparing.  What are you referring to?




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux