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 20, 2022, 17:37 UTC
Message-ID
<xmqqbktj3ct7.fsf@gitster.g>
In-Reply-To
<pull.1262.v8.git.1658334983053.gitgitgadget@gmail.com>
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:
It's been quite many iterations, so I'll just comment on the range-diff.
>      -+			usage_msg_opt("--format cannot used with -s, -o, -k, -t"
>      ++			usage_msg_opt("--format cannot used with -s, -o, -k, -t, "
>       +				      "--resolve-undo, --deduplicate, --eol",
>       +				      ls_files_usage, builtin_ls_files_options);
Looks good.
Show 9 quoted lines
>      @@ t/t3013-ls-files-format.sh (new)
>       +	printf "LINEONE\nLINETWO\nLINETHREE\n" >o1.txt &&
>       +	printf "LINEONE\r\nLINETWO\r\nLINETHREE\r\n" >o2.txt &&
>       +	printf "LINEONE\r\nLINETWO\nLINETHREE\n" >o3.txt &&
>      -+	ln -s o3.txt o4.txt &&
>      -+	git add "*.txt" &&
>      -+	git add --chmod +x o1.txt &&
>      -+	git update-index --add --cacheinfo 160000 $(git hash-object o1.txt) o5.txt &&
>      ++	git add . &&

We may want to be a bit more strict (like "o?.txt") but because we know this is the first 'setup' step, let's let it pass.

>      ++	oid=$(git hash-object o1.txt) &&
>      ++	git update-index --add --cacheinfo 120000 $oid o4.txt &&
>      ++	git update-index --add --cacheinfo 160000 $oid o5.txt &&
>      ++	git update-index --add --cacheinfo 100755 $oid o6.txt &&

It is a bit inconvenient that --cacheinfo takes only fully-spelled raw object name that we need to use $oid like this (otherwise we would be able to write ":o1.txt" instead), but (1) it is not a fault of this patch, and (2) update-index is a plumbing command meant for scripts, so it is not too big a problem.

Show 7 quoted lines
>       +	git commit -m base
>       +'
>       +
>       +test_expect_success 'git ls-files --format objectmode v.s. -s' '
>      -+	git ls-files -s | awk "{print \$1}" >expect &&
>      ++	git ls-files -s >files &&
>      ++	cut -d" " -f1 files >expect &&

Either "awk" or "cut" is fine and flipping between them is a bit distracting. Cutting the pipe into two is a good move.

But is this testing the right thing?
Show 6 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

I do not know if the $format I wrote without looking at the doc is correct, but you get the idea.

Thanks.
Previous: ZheNing Hu via GitGitGadgetNext: Ævar Arnfjörð Bjarmason
Message 49 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.