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

[PATCH v3 0/5] merge-tree: handle missing objects correctly

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 22, 2024, 14:36 UTC
Message-ID
<pull.1651.v3.git.1708612605.gitgitgadget@gmail.com>
In-Reply-To
<pull.1651.v2.git.1707324461.gitgitgadget@gmail.com>

I recently looked into issues where git merge-tree calls returned bogus data (in one instance returning an empty tree for non-empty merge parents). By the time I had a look at the corresponding repository, the issue was no longer reproducible, but a closer look at the code combined with some manual experimenting turned up the fact that missing tree objects aren't handled as errors by git merge-tree.

While at it, I added a commit on top that tries to catch all remaining unchecked parse_tree() calls.

This patch series is based on 5f43cf5b2e4 (merge-tree: accept 3 trees as arguments, 2024-01-28) (the original tip commit of js/merge-tree-3-trees) because I introduced three unchecked parse_tree() calls in that topic.

Changes since v2:
 * Fixed the new "missing tree object" test case in t4301 that succeeded for
   the wrong reason.
 * Adjusted the new "missing blob object" test case to avoid succeeding for
   the wrong reason.
 * Simplified the "missing blob object" test case.
Changes since v1:
 * Simplified the test case, avoiding a subshell and a pipe in the process.
 * Added a patch to remove a superfluous subtree->object.parsed guard around
   a parse_tree(subtree) call.
Johannes Schindelin (5):
  merge-tree: fail with a non-zero exit code on missing tree objects
  merge-ort: do check `parse_tree()`'s return value
  t4301: verify that merge-tree fails on missing blob objects
  Always check `parse_tree*()`'s return value
  cache-tree: avoid an unnecessary check
 builtin/checkout.c               | 19 ++++++++++++++++---
 builtin/clone.c                  |  3 ++-
 builtin/commit.c                 |  3 ++-
 builtin/merge-tree.c             |  6 ++++++
 builtin/read-tree.c              |  3 ++-
 builtin/reset.c                  |  4 ++++
 cache-tree.c                     |  4 ++--
 merge-ort.c                      | 16 +++++++++++-----
 merge-recursive.c                |  3 ++-
 merge.c                          |  5 ++++-
 reset.c                          |  5 +++++
 sequencer.c                      |  4 ++++
 t/t4301-merge-tree-write-tree.sh | 27 +++++++++++++++++++++++++++
 13 files changed, 87 insertions(+), 15 deletions(-)
base-commit: 5f43cf5b2e4b68386d3774bce880b0f74d801635
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1651%2Fdscho%2Fmerge-tree-and-missing-objects-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1651/dscho/merge-tree-and-missing-objects-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1651
Range-diff vs v2:
 1:  01dfd66568c ! 1:  11b9cd8c5da merge-tree: fail with a non-zero exit code on missing tree objects
     @@ t/t4301-merge-tree-write-tree.sh: test_expect_success '--merge-base with tree OI
      +test_expect_success 'error out on missing tree objects' '
      +	git init --bare missing-tree.git &&
      +	git rev-list side3 >list &&
     -+	git rev-parse side3^: >list &&
     ++	git rev-parse side3^: >>list &&
      +	git pack-objects missing-tree.git/objects/pack/side3-tree-is-missing <list &&
      +	side3=$(git rev-parse side3) &&
     -+	test_must_fail git --git-dir=missing-tree.git merge-tree $side3^ $side3 >actual &&
     ++	test_must_fail git --git-dir=missing-tree.git merge-tree $side3^ $side3 >actual 2>err &&
     ++	test_grep "Could not read $(git rev-parse $side3:)" err &&
      +	test_must_be_empty actual
      +'
      +
 2:  a1bbb7e06e5 = 2:  f01f4eb011b merge-ort: do check `parse_tree()`'s return value
 3:  be1dadf2850 ! 3:  e82fdf7fbcb t4301: verify that merge-tree fails on missing blob objects
     @@ t/t4301-merge-tree-write-tree.sh: test_expect_success 'error out on missing tree
       '
       
      +test_expect_success 'error out on missing blob objects' '
     -+	seq1=$(test_seq 1 10 | git hash-object -w --stdin) &&
     -+	seq2=$(test_seq 1 11 | git hash-object -w --stdin) &&
     -+	seq3=$(test_seq 0 10 | git hash-object -w --stdin) &&
     -+	tree1=$(printf "100644 blob %s\tsequence" $seq1 | git mktree) &&
     -+	tree2=$(printf "100644 blob %s\tsequence" $seq2 | git mktree) &&
     -+	tree3=$(printf "100644 blob %s\tsequence" $seq3 | git mktree) &&
     ++	echo 1 | git hash-object -w --stdin >blob1 &&
     ++	echo 2 | git hash-object -w --stdin >blob2 &&
     ++	echo 3 | git hash-object -w --stdin >blob3 &&
     ++	printf "100644 blob $(cat blob1)\tblob\n" | git mktree >tree1 &&
     ++	printf "100644 blob $(cat blob2)\tblob\n" | git mktree >tree2 &&
     ++	printf "100644 blob $(cat blob3)\tblob\n" | git mktree >tree3 &&
      +	git init --bare missing-blob.git &&
     -+	test_write_lines $seq1 $seq3 $tree1 $tree2 $tree3 |
     ++	cat blob1 blob3 tree1 tree2 tree3 |
      +	git pack-objects missing-blob.git/objects/pack/side1-whatever-is-missing &&
     -+	test_must_fail git --git-dir=missing-blob.git merge-tree --merge-base=$tree1 $tree2 $tree3 >actual &&
     ++	test_must_fail git --git-dir=missing-blob.git >actual 2>err \
     ++		merge-tree --merge-base=$(cat tree1) $(cat tree2) $(cat tree3) &&
     ++	test_grep "unable to read blob object $(cat blob2)" err &&
      +	test_must_be_empty actual
      +'
      +
 4:  ffd38ad602a = 4:  9e4dc94ef03 Always check `parse_tree*()`'s return value
 5:  43c04749513 = 5:  91dc4ccd04e cache-tree: avoid an unnecessary check
-- 
gitgitgadget
Previous: Junio C HamanoNext: Johannes Schindelin via GitGitGadget
Message 27 of 48 in “merge-tree: handle missing objects correctly”
  1. 0/4 merge-tree: handle missing objects correctlyJohannes Schindelin via GitGitGadget, Feb 6, 2024
  2. 1/4 merge-tree: fail with a non-zero exit code on missing tree objectsJohannes Schindelin via GitGitGadget, Feb 6, 2024
  3. Patrick SteinhardtFeb 7, 2024
  4. 2/4 merge-ort: do check `parse_tree()`'s return valueJohannes Schindelin via GitGitGadget, Feb 6, 2024
  5. 3/4 t4301: verify that merge-tree fails on missing blob objectsJohannes Schindelin via GitGitGadget, Feb 6, 2024
  6. 4/4 Always check `parse_tree*()`'s return valueJohannes Schindelin via GitGitGadget, Feb 6, 2024
  7. Junio C HamanoFeb 6, 2024
  8. Patrick SteinhardtFeb 7, 2024
  9. Junio C HamanoFeb 6, 2024
  10. Patrick SteinhardtFeb 7, 2024
  11. 0/5 merge-tree: handle missing objects correctlyJohannes Schindelin via GitGitGadget, Feb 7, 2024
  12. 1/5 merge-tree: fail with a non-zero exit code on missing tree objectsJohannes Schindelin via GitGitGadget, Feb 7, 2024
  13. Eric SunshineFeb 7, 2024
  14. Johannes SchindelinFeb 22, 2024
  15. 2/5 merge-ort: do check `parse_tree()`'s return valueJohannes Schindelin via GitGitGadget, Feb 7, 2024
  16. 3/5 t4301: verify that merge-tree fails on missing blob objectsJohannes Schindelin via GitGitGadget, Feb 7, 2024
  17. Eric SunshineFeb 7, 2024
  18. Junio C HamanoFeb 7, 2024
  19. Eric SunshineFeb 8, 2024
  20. Johannes SchindelinFeb 22, 2024
  21. 4/5 Always check `parse_tree*()`'s return valueJohannes Schindelin via GitGitGadget, Feb 7, 2024
  22. Eric SunshineFeb 7, 2024
  23. Johannes SchindelinFeb 22, 2024
  24. Junio C HamanoFeb 22, 2024
  25. 5/5 cache-tree: avoid an unnecessary checkJohannes Schindelin via GitGitGadget, Feb 7, 2024
  26. Junio C HamanoFeb 7, 2024
  27. 0/5 merge-tree: handle missing objects correctlyJohannes Schindelin via GitGitGadget, Feb 22, 2024
  28. 1/5 merge-tree: fail with a non-zero exit code on missing tree objectsJohannes Schindelin via GitGitGadget, Feb 22, 2024
  29. Junio C HamanoFeb 22, 2024
  30. 2/5 merge-ort: do check `parse_tree()`'s return valueJohannes Schindelin via GitGitGadget, Feb 22, 2024
  31. Junio C HamanoFeb 22, 2024
  32. 3/5 t4301: verify that merge-tree fails on missing blob objectsJohannes Schindelin via GitGitGadget, Feb 22, 2024
  33. Junio C HamanoFeb 22, 2024
  34. Junio C HamanoFeb 22, 2024
  35. 4/5 Always check `parse_tree*()`'s return valueJohannes Schindelin via GitGitGadget, Feb 22, 2024
  36. Junio C HamanoFeb 22, 2024
  37. Johannes SchindelinFeb 23, 2024
  38. Junio C HamanoFeb 23, 2024
  39. 5/5 cache-tree: avoid an unnecessary checkJohannes Schindelin via GitGitGadget, Feb 22, 2024
  40. Junio C HamanoFeb 22, 2024
  41. 0/6 merge-tree: handle missing objects correctlyJohannes Schindelin via GitGitGadget, Feb 23, 2024
  42. 1/6 merge-tree: fail with a non-zero exit code on missing tree objectsJohannes Schindelin via GitGitGadget, Feb 23, 2024
  43. 2/6 merge-ort: do check `parse_tree()`'s return valueJohannes Schindelin via GitGitGadget, Feb 23, 2024
  44. 3/6 t4301: verify that merge-tree fails on missing blob objectsJohannes Schindelin via GitGitGadget, Feb 23, 2024
  45. 4/6 Always check `parse_tree*()`'s return valueJohannes Schindelin via GitGitGadget, Feb 23, 2024
  46. 5/6 cache-tree: avoid an unnecessary checkJohannes Schindelin via GitGitGadget, Feb 23, 2024
  47. 6/6 fill_tree_descriptor(): mark error message for translationJohannes Schindelin via GitGitGadget, Feb 23, 2024
  48. Junio C HamanoFeb 23, 2024

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.