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

[PATCH v2 3/5] t/t5318-commit-graph.sh: test generation zero transitions during fsck

From
Taylor Blau <me@ttaylorr.com>
Date
Aug 11, 2023, 17:05 UTC
Message-ID
<8679db3d0e895bef7f9a12d8d6742ca812768241.1691773533.git.me@ttaylorr.com>
In-Reply-To
<cover.1691773533.git.me@ttaylorr.com>

The second test called "detect incorrect generation number" asserts that we correctly warn during an fsck when we see a non-zero generation number after seeing a zero beforehand.

The other transition (going from non-zero to zero) was previously untested. Test both directions, and rename the existing test to make clear which direction it is exercising.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 t/t5318-commit-graph.sh | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index 4e70820c74..8e96471b34 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -450,14 +450,15 @@ GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
 GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
 GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
 GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
+GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
 GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
 GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
 GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
 GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
 GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
 GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
+GRAPH_BYTE_COMMIT_GENERATION_LAST=$(($GRAPH_BYTE_COMMIT_GENERATION + $(($NUM_COMMITS - 1)) * $GRAPH_COMMIT_DATA_WIDTH))
 GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
-GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
 GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
 			     $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
 GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
@@ -596,11 +597,6 @@ test_expect_success 'detect incorrect generation number' '
 		"generation for commit"
 '
 
-test_expect_success 'detect incorrect generation number' '
-	corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
-		"but zero elsewhere"
-'
-
 test_expect_success 'detect incorrect commit date' '
 	corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
 		"commit date"
@@ -622,6 +618,16 @@ test_expect_success 'detect incorrect chunk count' '
 		$GRAPH_CHUNK_LOOKUP_OFFSET
 '
 
+test_expect_success 'detect mixed generation numbers (non-zero to zero)' '
+	corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION_LAST "\0\0\0\0" \
+		"but non-zero elsewhere"
+'
+
+test_expect_success 'detect mixed generation numbers (zero to non-zero)' '
+	corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\0\0\0\0" \
+		"but zero elsewhere"
+'
+
 test_expect_success 'git fsck (checks commit-graph when config set to true)' '
 	git -C full fsck &&
 	corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
-- 
2.42.0.rc0.30.gb82b15ebc8
Previous: Taylor BlauNext: Taylor Blau
Message 16 of 30 in “commit-graph: verify swapped zero/non-zero generation cases”
  1. commit-graph: verify swapped zero/non-zero generation casesJeff King, Aug 8, 2023
  2. Taylor BlauAug 10, 2023
  3. Taylor BlauAug 10, 2023
  4. 0/4 commit-graph: fsck zero/non-zero generation number fixesTaylor Blau, Aug 10, 2023
  5. 1/4 commit-graph: introduce `commit_graph_generation_from_graph()`Taylor Blau, Aug 10, 2023
  6. 2/4 commit-graph: verify swapped zero/non-zero generation casesTaylor Blau, Aug 10, 2023
  7. Junio C HamanoAug 10, 2023
  8. Jeff KingAug 11, 2023
  9. Taylor BlauAug 11, 2023
  10. 3/4 t/t5318-commit-graph.sh: test generation zero transitions during fsckTaylor Blau, Aug 10, 2023
  11. 4/4 commit-graph: invert negated conditionalTaylor Blau, Aug 10, 2023
  12. Jeff KingAug 11, 2023
  13. 0/5 commit-graph: fsck zero/non-zero generation number fixesTaylor Blau, Aug 11, 2023
  14. 1/5 commit-graph: introduce `commit_graph_generation_from_graph()`Taylor Blau, Aug 11, 2023
  15. 2/5 commit-graph: verify swapped zero/non-zero generation casesTaylor Blau, Aug 11, 2023
  16. 3/5 t/t5318-commit-graph.sh: test generation zero transitions during fsckTaylor Blau, Aug 11, 2023
  17. 4/5 commit-graph: invert negated conditional, extract to functionTaylor Blau, Aug 11, 2023
  18. 5/5 commit-graph: avoid repeated mixed generation number warningsTaylor Blau, Aug 11, 2023
  19. Jeff KingAug 11, 2023
  20. Junio C HamanoAug 11, 2023
  21. Jeff KingAug 17, 2023
  22. Taylor BlauAug 21, 2023
  23. 0/4 commit-graph: fsck zero/non-zero generation number fixesTaylor Blau, Aug 21, 2023
  24. 1/4 commit-graph: introduce `commit_graph_generation_from_graph()`Taylor Blau, Aug 21, 2023
  25. 2/4 commit-graph: verify swapped zero/non-zero generation casesTaylor Blau, Aug 21, 2023
  26. 3/4 t/t5318-commit-graph.sh: test generation zero transitions during fsckTaylor Blau, Aug 21, 2023
  27. 4/4 commit-graph: commit-graph: avoid repeated mixed generation number warningsTaylor Blau, Aug 21, 2023
  28. Jeff KingAug 21, 2023
  29. Junio C HamanoAug 21, 2023
  30. Taylor BlauAug 23, 2023

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.