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

[PATCH 04/11] unpack-trees: clean up some flow control

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 23, 2023, 09:14 UTC
Message-ID
<f5a58123034a708b49aac7076197ad2ccdd3cba1.1677143700.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1149.git.1677143700.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

The update_sparsity() function was introduced in commit 7af7a25853 ("unpack-trees: add a new update_sparsity() function", 2020-03-27). Prior to that, unpack_trees() was used, but that had a few bugs because the needs of the caller were different, and different enough that unpack_trees() could not easily be modified to handle both usecases.

The implementation detail that update_sparsity() was written by copying unpack_trees() and then streamlining it, and then modifying it in the needed ways still shows through in that there are leftover vestiges in both functions that are no longer needed. Clean them up. In particular:

  * update_sparsity() allows a pattern list to be passed in, but
    unpack_trees() never should use a different pattern list.  Add a
    check and a BUG() if this gets violated.
  * update_sparsity() has a check early on that will BUG() if
    o->skip_sparse_checkout is set; as such, there's no need to check
    for that condition again later in the code.  We can simply remove
    the check and its corresponding goto label.
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 unpack-trees.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 3d05e45a279..0887d157df4 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1873,6 +1873,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 		die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
 	if (o->dir)
 		BUG("o->dir is for internal use only");
+	if (o->pl)
+		BUG("o->pl is for internal use only");
 
 	trace_performance_enter();
 	trace2_region_enter("unpack_trees", "unpack_trees", the_repository);
@@ -1899,7 +1901,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 
 	if (!core_apply_sparse_checkout || !o->update)
 		o->skip_sparse_checkout = 1;
-	if (!o->skip_sparse_checkout && !o->pl) {
+	if (!o->skip_sparse_checkout) {
 		memset(&pl, 0, sizeof(pl));
 		free_pattern_list = 1;
 		populate_from_existing_patterns(o, &pl);
@@ -2113,8 +2115,6 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
 		memset(&pl, 0, sizeof(pl));
 		free_pattern_list = 1;
 		populate_from_existing_patterns(o, &pl);
-		if (o->skip_sparse_checkout)
-			goto skip_sparse_checkout;
 	}
 
 	/* Expand sparse directories as needed */
@@ -2142,7 +2142,6 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
 			ret = UPDATE_SPARSITY_WARNINGS;
 	}
 
-skip_sparse_checkout:
 	if (check_updates(o, o->src_index))
 		ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES;
 
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Jonathan Tan
Message 9 of 57 in “Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internal”
  1. 00/11 Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internalElijah Newren via GitGitGadget, Feb 23, 2023
  2. 01/11 dir: separate public from internal portion of dir_structElijah Newren via GitGitGadget, Feb 23, 2023
  3. 02/11 dir: add a usage note to exclude_per_dirElijah Newren via GitGitGadget, Feb 23, 2023
  4. Jonathan TanFeb 24, 2023
  5. Elijah NewrenFeb 25, 2023
  6. Jonathan TanFeb 25, 2023
  7. Elijah NewrenFeb 25, 2023
  8. 03/11 dir: mark output only fields of dir_struct as suchElijah Newren via GitGitGadget, Feb 23, 2023
  9. 04/11 unpack-trees: clean up some flow controlElijah Newren via GitGitGadget, Feb 23, 2023
  10. Jonathan TanFeb 24, 2023
  11. 05/11 sparse-checkout: avoid using internal API of unpack-treesElijah Newren via GitGitGadget, Feb 23, 2023
  12. Jonathan TanFeb 24, 2023
  13. Elijah NewrenFeb 25, 2023
  14. 06/11 sparse-checkout: avoid using internal API of unpack-trees, take 2Elijah Newren via GitGitGadget, Feb 23, 2023
  15. Jonathan TanFeb 24, 2023
  16. Elijah NewrenFeb 25, 2023
  17. 07/11 unpack_trees: start splitting internal fields from public APIElijah Newren via GitGitGadget, Feb 23, 2023
  18. 09/11 unpack-trees: rewrap a few overlong lines from previous patchElijah Newren via GitGitGadget, Feb 23, 2023
  19. 10/11 unpack-trees: special case read-tree debugging as internal usageElijah Newren via GitGitGadget, Feb 23, 2023
  20. 08/11 unpack-trees: mark fields only used internally as internalElijah Newren via GitGitGadget, Feb 23, 2023
  21. 11/11 unpack-trees: add usage notices around df_conflict_entryElijah Newren via GitGitGadget, Feb 23, 2023
  22. Derrick StoleeFeb 23, 2023
  23. Derrick StoleeFeb 23, 2023
  24. Elijah NewrenFeb 23, 2023
  25. Elijah NewrenFeb 23, 2023
  26. Junio C HamanoFeb 24, 2023
  27. Jacob KellerFeb 24, 2023
  28. Jonathan TanFeb 24, 2023
  29. 00/11 Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internalElijah Newren via GitGitGadget, Feb 25, 2023
  30. 02/11 dir: add a usage note to exclude_per_dirElijah Newren via GitGitGadget, Feb 25, 2023
  31. 01/11 dir: separate public from internal portion of dir_structElijah Newren via GitGitGadget, Feb 25, 2023
  32. 03/11 dir: mark output only fields of dir_struct as suchElijah Newren via GitGitGadget, Feb 25, 2023
  33. 04/11 unpack-trees: clean up some flow controlElijah Newren via GitGitGadget, Feb 25, 2023
  34. 05/11 sparse-checkout: avoid using internal API of unpack-treesElijah Newren via GitGitGadget, Feb 25, 2023
  35. 06/11 sparse-checkout: avoid using internal API of unpack-trees, take 2Elijah Newren via GitGitGadget, Feb 25, 2023
  36. 09/11 unpack-trees: rewrap a few overlong lines from previous patchElijah Newren via GitGitGadget, Feb 25, 2023
  37. 07/11 unpack_trees: start splitting internal fields from public APIElijah Newren via GitGitGadget, Feb 25, 2023
  38. 11/11 unpack-trees: add usage notices around df_conflict_entryElijah Newren via GitGitGadget, Feb 25, 2023
  39. 10/11 unpack-trees: special case read-tree debugging as internal usageElijah Newren via GitGitGadget, Feb 25, 2023
  40. 08/11 unpack-trees: mark fields only used internally as internalElijah Newren via GitGitGadget, Feb 25, 2023
  41. Junio C HamanoFeb 25, 2023
  42. 00/13 Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internalElijah Newren via GitGitGadget, Feb 27, 2023
  43. 01/13 t2021: fix platform-specific leftover cruftElijah Newren via GitGitGadget, Feb 27, 2023
  44. Derrick StoleeFeb 27, 2023
  45. 02/13 unpack-trees: heed requests to overwrite ignored filesElijah Newren via GitGitGadget, Feb 27, 2023
  46. Jonathan TanFeb 27, 2023
  47. 03/13 dir: separate public from internal portion of dir_structElijah Newren via GitGitGadget, Feb 27, 2023
  48. 05/13 dir: mark output only fields of dir_struct as suchElijah Newren via GitGitGadget, Feb 27, 2023
  49. 04/13 dir: add a usage note to exclude_per_dirElijah Newren via GitGitGadget, Feb 27, 2023
  50. 07/13 sparse-checkout: avoid using internal API of unpack-treesElijah Newren via GitGitGadget, Feb 27, 2023
  51. 06/13 unpack-trees: clean up some flow controlElijah Newren via GitGitGadget, Feb 27, 2023
  52. 08/13 sparse-checkout: avoid using internal API of unpack-trees, take 2Elijah Newren via GitGitGadget, Feb 27, 2023
  53. 10/13 unpack-trees: mark fields only used internally as internalElijah Newren via GitGitGadget, Feb 27, 2023
  54. 09/13 unpack_trees: start splitting internal fields from public APIElijah Newren via GitGitGadget, Feb 27, 2023
  55. 11/13 unpack-trees: rewrap a few overlong lines from previous patchElijah Newren via GitGitGadget, Feb 27, 2023
  56. 12/13 unpack-trees: special case read-tree debugging as internal usageElijah Newren via GitGitGadget, Feb 27, 2023
  57. 13/13 unpack-trees: add usage notices around df_conflict_entryElijah Newren via GitGitGadget, Feb 27, 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.