Re: [PATCH v8] ls-files: introduce "--format" option
Junio C Hamano <gitster@pobox.com> 于2022年7月24日周日 02:40写道:
Show 41 quoted lines
>
> ZheNing Hu <adlternative@gmail.com> writes:
>
> >> But is this testing the right thing?
> >
> > Yes, I am sure about that cut can do the same thing as awk, and it can
> > specify its delimiter.
>
> That is not an answer to "is this testing the right thing?"
> question, though ;-)
>
> >> > +test_expect_success 'git ls-files --format objectmode v.s. -s' '
> >> > + git ls-files -s >files &&
> >> > + cut -d" " -f1 files >expect &&
> >> > + git ls-files --format="%(objectmode)" >actual &&
> >> > + test_cmp expect actual
> >> > +'
> >>
> >> It only looks at the first column of the "-s" output, and we are
> >> implicitly assuming that the order of output does not change between
> >> the "-s" output and "--format=<format>" output. I wonder if it is
> >> more useful and less error prone to come up with a format string
> >> that 100% reproduces the "ls-files -s" output and compare the two,
> >> e.g.
> >>
> >> format="%(objectmode) %(objectname) %(stage) %(path)" &&
> >> git ls-files -s >expect &&
> >> git ls-files --format="$format" >actual &&
> >> test_cmp expect actual
> >>
> >
> > See test case: 'git ls-files --format imitate --stage' which just do such thing,
>
>
> That was not the point. By extracting only "%(objectmode)" without
> having any other clues (like "%(path)") on the same line, the test
> is assuming that ls-files will always sort its output in the same
> order regardless of the output format, whether it is "--stage" or
> "--format=<spec>", and that was what the "is this testing the right
> thing?" question was about.
>
Ah, so that we should sort the ls-files output first, and then compare them.
Show 10 quoted lines
> The other test that makes sure --format=<spec> can recreate --stage
> output is fine. If some future developer breaks the output order by
> mistake for --format=<spec>, we will catch such a mistake with it.
>
>
> > maybe I should change its name to 'git ls-files --format v.s. -s'?
>
> I do not think you should. "A v.s. B" does not imply "A and B
> should create identical result". The original title describes what
> it does much more clearly.
Ok, here I don't need another rerolling to revert it, right?
Thanks for all the reviews!
ZheNing Hu