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

Re: [PATCH v2 01/10] ls-files: add --json to dump the index

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 25, 2019, 11:31 UTC
Message-ID
<nycvar.QRO.7.76.6.1906251328320.44@tvgsbejvaqbjf.bet>
In-Reply-To
<nycvar.QRO.7.76.6.1906251142580.44@tvgsbejvaqbjf.bet>
Hi Duy,
On Tue, 25 Jun 2019, Johannes Schindelin wrote:
Show 24 quoted lines
> On Mon, 24 Jun 2019, Nguyễn Thái Ngọc Duy wrote:
>
> > diff --git a/t/t3011-ls-files-json.sh b/t/t3011-ls-files-json.sh
> > new file mode 100755
> > index 0000000000..97bcd814be
> > --- /dev/null
> > +++ b/t/t3011-ls-files-json.sh
> > @@ -0,0 +1,44 @@
> > +#!/bin/sh
> > +
> > +test_description='ls-files dumping json'
> > +
> > +. ./test-lib.sh
> > +
> > +strip_number() {
> > +	for name; do
> > +		echo 's/\("'$name'":\) [0-9]\+/\1 <number>/' >>filter.sed
>
> This does not do what you think it does, in Ubuntu Xenial and on macOS:
>
> https://dev.azure.com/gitgitgadget/git/_build/results?buildId=11408&view=ms.vss-test-web.build-test-results-tab&runId=27736&paneView=debug&resultId=105613
>
> The `\1` is expanded to the ASCII character 001. Therefore your test cases
> fail on almost all platforms.

The `strip_number()`/`strip_string()` approach might look elegant from a design perspective, but from a readability perspective (and obviously, when one wants to make those tests more robust and cross-platform), it would be a lot better to do it more explicitly.

This patch on top of your patch series makes the test run correctly in my Linux and Windows setup, and much easier to understand:

-- snipsnap --
diff --git a/t/t3011-ls-files-json.sh b/t/t3011-ls-files-json.sh
index 9f4ad4c9cf..8b782c48e0 100755
--- a/t/t3011-ls-files-json.sh
+++ b/t/t3011-ls-files-json.sh
@@ -4,18 +4,6 @@ test_description='ls-files dumping json'

 . ./test-lib.sh

-strip_number() {
-	for name; do
-		echo 's/\("'$name'":\) [0-9]\+/\1 <number>/' >>filter.sed
-	done
-}
-
-strip_string() {
-	for name; do
-		echo 's/\("'$name'":\) ".*"/\1 <string>/' >>filter.sed
-	done
-}
-
 compare_json() {
 	git ls-files --debug-json >json &&
 	sed -f filter.sed json >filtered &&
@@ -35,9 +23,21 @@ test_expect_success 'setup' '
 	echo intent-to-add >ita &&
 	git add -N ita &&

-	strip_number ctime_sec ctime_nsec mtime_sec mtime_nsec &&
-	strip_number device inode uid gid file_offset ext_size last_update &&
-	strip_string oid ident
+	cat >filter.sed <<-\EOF
+	s/\("ctime_sec":\) [0-9]\+/\1 <number>/
+	s/\("ctime_nsec":\) [0-9]\+/\1 <number>/
+	s/\("mtime_sec":\) [0-9]\+/\1 <number>/
+	s/\("mtime_nsec":\) [0-9]\+/\1 <number>/
+	s/\("device":\) [0-9]\+/\1 <number>/
+	s/\("inode":\) [0-9]\+/\1 <number>/
+	s/\("uid":\) [0-9]\+/\1 <number>/
+	s/\("gid":\) [0-9]\+/\1 <number>/
+	s/\("file_offset":\) [0-9]\+/\1 <number>/
+	s/\("ext_size":\) [0-9]\+/\1 <number>/
+	s/\("last_update":\) [0-9]\+/\1 <number>/
+	s/\("oid":\) ".*"/\1 <string>/
+	s/\("ident":\) ".*"/\1 <string>/
+	EOF
 '

 test_expect_success 'ls-files --json, main entries, UNTR and TREE' '
@@ -98,7 +98,9 @@ test_expect_success !SINGLE_CPU 'ls-files --json and multicore extensions' '
 		touch one two three four &&
 		git add . &&
 		cp ../filter.sed . &&
-		strip_number offset &&
+		cat >>filter.sed <<-\EOF &&
+		s/\("offset":\) [0-9]\+/\1 <number>/
+		EOF
 		compare_json eoie
 	)
 '
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 10 of 43 in “Add 'ls-files --debug-json' to dump the index in json”
  1. 00/10 Add 'ls-files --debug-json' to dump the index in jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  2. 01/10 ls-files: add --json to dump the indexNguyễn Thái Ngọc Duy, Jun 24, 2019
  3. Jeff HostetlerJun 24, 2019
  4. Junio C HamanoJun 24, 2019
  5. Johannes SchindelinJun 25, 2019
  6. Duy NguyenJun 25, 2019
  7. Jeff HostetlerJun 25, 2019
  8. Thomas GummererJun 25, 2019
  9. Johannes SchindelinJun 25, 2019
  10. Johannes SchindelinJun 25, 2019
  11. Johannes SchindelinJun 25, 2019
  12. Junio C HamanoJun 25, 2019
  13. Junio C HamanoJun 26, 2019
  14. 02/10 read-cache.c: dump common extension info in jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  15. 03/10 cache-tree.c: dump "TREE" extension as jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  16. 04/10 dir.c: dump "UNTR" extension as jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  17. Jeff HostetlerJun 24, 2019
  18. 05/10 split-index.c: dump "link" extension as jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  19. Jeff HostetlerJun 24, 2019
  20. Duy NguyenJun 25, 2019
  21. Derrick StoleeJun 25, 2019
  22. Duy NguyenJun 27, 2019
  23. Jeff HostetlerJun 27, 2019
  24. Derrick StoleeJun 27, 2019
  25. Duy NguyenJun 27, 2019
  26. SZEDER GáborJul 3, 2019
  27. SZEDER GáborJul 4, 2019
  28. Duy NguyenJul 4, 2019
  29. Junio C HamanoJul 8, 2019
  30. 06/10 fsmonitor.c: dump "FSMN" extension as jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  31. 07/10 resolve-undo.c: dump "REUC" extension as jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  32. 09/10 read-cache.c: dump "IEOT" extension as jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  33. 08/10 read-cache.c: dump "EOIE" extension as jsonNguyễn Thái Ngọc Duy, Jun 24, 2019
  34. 10/10 t3008: use the new SINGLE_CPU prereqNguyễn Thái Ngọc Duy, Jun 24, 2019
  35. Johannes SchindelinJun 24, 2019
  36. Jeff HostetlerJun 24, 2019
  37. Duy NguyenJun 25, 2019
  38. Thomas GummererJun 25, 2019
  39. Johannes SchindelinJun 25, 2019
  40. Duy NguyenJun 25, 2019
  41. Johannes SchindelinJun 25, 2019
  42. Ramsay JonesJun 25, 2019
  43. Johannes SchindelinJun 26, 2019

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.