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

Re: [PATCH v8] ls-files: introduce "--format" option

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 23, 2022, 18:40 UTC
Message-ID
<xmqqsfmr8ygp.fsf@gitster.g>
In-Reply-To
<CAOLTT8RjLoooT7t+ucFqa9P=8TiVL3M+ZgcEY7qVhRbjB=9OhA@mail.gmail.com>
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 ;-)

Show 21 quoted lines
>> > +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.

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.

Previous: ZheNing HuNext: Junio C Hamano
Message 54 of 61 in “ls-files: introduce "--format" and "--object-only" options”
  1. 0/2 ls-files: introduce "--format" and "--object-only" optionsZheNing Hu via GitGitGadget, Jun 15, 2022
  2. 1/2 ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jun 15, 2022
  3. Ævar Arnfjörð BjarmasonJun 15, 2022
  4. ZheNing HuJun 18, 2022
  5. 2/2 ls-files: introduce "--object-only" optionZheNing Hu via GitGitGadget, Jun 15, 2022
  6. Ævar Arnfjörð BjarmasonJun 15, 2022
  7. ZheNing HuJun 18, 2022
  8. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jun 19, 2022
  9. Phillip WoodJun 19, 2022
  10. ZheNing HuJun 20, 2022
  11. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jun 21, 2022
  12. Phillip WoodJun 23, 2022
  13. Junio C HamanoJun 23, 2022
  14. Phillip WoodJun 24, 2022
  15. ZheNing HuJun 26, 2022
  16. Ævar Arnfjörð BjarmasonJun 24, 2022
  17. Junio C HamanoJun 24, 2022
  18. ZheNing HuJun 26, 2022
  19. Ævar Arnfjörð BjarmasonJun 24, 2022
  20. Junio C HamanoJun 24, 2022
  21. ZheNing HuJun 26, 2022
  22. Junio C HamanoJun 27, 2022
  23. ZheNing HuJun 27, 2022
  24. Junio C HamanoJun 27, 2022
  25. ZheNing HuJul 1, 2022
  26. ZheNing HuJun 26, 2022
  27. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jun 26, 2022
  28. Junio C HamanoJun 27, 2022
  29. ZheNing HuJun 27, 2022
  30. Ævar Arnfjörð BjarmasonJun 27, 2022
  31. ZheNing HuJul 1, 2022
  32. Phillip WoodJun 28, 2022
  33. ZheNing HuJul 1, 2022
  34. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jul 5, 2022
  35. Ævar Arnfjörð BjarmasonJul 5, 2022
  36. ZheNing HuJul 11, 2022
  37. Torsten BögershausenJul 5, 2022
  38. ZheNing HuJul 11, 2022
  39. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jul 11, 2022
  40. Junio C HamanoJul 11, 2022
  41. ZheNing HuJul 12, 2022
  42. Junio C HamanoJul 12, 2022
  43. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jul 13, 2022
  44. Ævar Arnfjörð BjarmasonJul 18, 2022
  45. ZheNing HuJul 19, 2022
  46. Junio C HamanoJul 19, 2022
  47. ZheNing HuJul 19, 2022
  48. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jul 20, 2022
  49. Junio C HamanoJul 20, 2022
  50. Ævar Arnfjörð BjarmasonJul 21, 2022
  51. Eric SunshineJul 21, 2022
  52. Junio C HamanoJul 21, 2022
  53. ZheNing HuJul 22, 2022
  54. Junio C HamanoJul 23, 2022
  55. Junio C HamanoJul 23, 2022
  56. ZheNing HuJul 24, 2022
  57. Junio C HamanoJul 25, 2022
  58. ZheNing HuJul 25, 2022
  59. ls-files: introduce "--format" optionZheNing Hu via GitGitGadget, Jul 23, 2022
  60. Jiang XinSep 8, 2022
  61. ZheNing HuSep 11, 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.