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

[PATCH 10/11] unpack-trees: special case read-tree debugging as internal usage

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

builtin/read-tree.c has some special functionality explicitly designed for debugging unpack-trees.[ch]. Associated with that is two fields that no other external caller would or should use. Mark these as internal to unpack-trees, but allow builtin/read-tree to read or write them for this special case.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/read-tree.c | 10 +++++-----
 unpack-trees.c      | 22 +++++++++++-----------
 unpack-trees.h      |  6 +++---
 3 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 3ce75417833..6034408d486 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -87,9 +87,9 @@ static int debug_merge(const struct cache_entry * const *stages,
 {
 	int i;
 
-	printf("* %d-way merge\n", o->merge_size);
+	printf("* %d-way merge\n", o->internal.merge_size);
 	debug_stage("index", stages[0], o);
-	for (i = 1; i <= o->merge_size; i++) {
+	for (i = 1; i <= o->internal.merge_size; i++) {
 		char buf[24];
 		xsnprintf(buf, sizeof(buf), "ent#%d", i);
 		debug_stage(buf, stages[i], o);
@@ -144,7 +144,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
 		OPT__DRY_RUN(&opts.dry_run, N_("don't update the index or the work tree")),
 		OPT_BOOL(0, "no-sparse-checkout", &opts.skip_sparse_checkout,
 			 N_("skip applying sparse checkout filter")),
-		OPT_BOOL(0, "debug-unpack", &opts.debug_unpack,
+		OPT_BOOL(0, "debug-unpack", &opts.internal.debug_unpack,
 			 N_("debug unpack-trees")),
 		OPT_CALLBACK_F(0, "recurse-submodules", NULL,
 			    "checkout", "control recursive updating of submodules",
@@ -247,7 +247,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
 			opts.head_idx = 1;
 	}
 
-	if (opts.debug_unpack)
+	if (opts.internal.debug_unpack)
 		opts.fn = debug_merge;
 
 	/* If we're going to prime_cache_tree later, skip cache tree update */
@@ -263,7 +263,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
 	if (unpack_trees(nr_trees, t, &opts))
 		return 128;
 
-	if (opts.debug_unpack || opts.dry_run)
+	if (opts.internal.debug_unpack || opts.dry_run)
 		return 0; /* do not write the index out */
 
 	/*
diff --git a/unpack-trees.c b/unpack-trees.c
index fa186a27ccc..60b6e38fd69 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -839,7 +839,7 @@ static int traverse_by_cache_tree(int pos, int nr_entries, int nr_names,
 		mark_ce_used(src[0], o);
 	}
 	free(tree_ce);
-	if (o->debug_unpack)
+	if (o->internal.debug_unpack)
 		printf("Unpacked %d entries from %s to %s using cache-tree\n",
 		       nr_entries,
 		       o->src_index->cache[pos]->name,
@@ -1488,7 +1488,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
 	while (!p->mode)
 		p++;
 
-	if (o->debug_unpack)
+	if (o->internal.debug_unpack)
 		debug_unpack_callback(n, mask, dirmask, names, info);
 
 	/* Are we supposed to look at the index too? */
@@ -1929,7 +1929,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 			init_split_index(&o->internal.result);
 	}
 	oidcpy(&o->internal.result.oid, &o->src_index->oid);
-	o->merge_size = len;
+	o->internal.merge_size = len;
 	mark_all_ce_unused(o->src_index);
 
 	o->internal.result.fsmonitor_last_update =
@@ -2880,9 +2880,9 @@ int twoway_merge(const struct cache_entry * const *src,
 	const struct cache_entry *oldtree = src[1];
 	const struct cache_entry *newtree = src[2];
 
-	if (o->merge_size != 2)
+	if (o->internal.merge_size != 2)
 		return error("Cannot do a twoway merge of %d trees",
-			     o->merge_size);
+			     o->internal.merge_size);
 
 	if (oldtree == o->df_conflict_entry)
 		oldtree = NULL;
@@ -2962,9 +2962,9 @@ int bind_merge(const struct cache_entry * const *src,
 	const struct cache_entry *old = src[0];
 	const struct cache_entry *a = src[1];
 
-	if (o->merge_size != 1)
+	if (o->internal.merge_size != 1)
 		return error("Cannot do a bind merge of %d trees",
-			     o->merge_size);
+			     o->internal.merge_size);
 	if (a && old)
 		return o->quiet ? -1 :
 			error(ERRORMSG(o, ERROR_BIND_OVERLAP),
@@ -2988,9 +2988,9 @@ int oneway_merge(const struct cache_entry * const *src,
 	const struct cache_entry *old = src[0];
 	const struct cache_entry *a = src[1];
 
-	if (o->merge_size != 1)
+	if (o->internal.merge_size != 1)
 		return error("Cannot do a oneway merge of %d trees",
-			     o->merge_size);
+			     o->internal.merge_size);
 
 	if (!a || a == o->df_conflict_entry)
 		return deleted_entry(old, old, o);
@@ -3025,8 +3025,8 @@ int stash_worktree_untracked_merge(const struct cache_entry * const *src,
 	const struct cache_entry *worktree = src[1];
 	const struct cache_entry *untracked = src[2];
 
-	if (o->merge_size != 2)
-		BUG("invalid merge_size: %d", o->merge_size);
+	if (o->internal.merge_size != 2)
+		BUG("invalid merge_size: %d", o->internal.merge_size);
 
 	if (worktree && untracked)
 		return error(_("worktree and untracked commit have duplicate entries: %s"),
diff --git a/unpack-trees.h b/unpack-trees.h
index 0335c89bc75..e8737adfeda 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -65,7 +65,6 @@ struct unpack_trees_options {
 		     skip_unmerged,
 		     initial_checkout,
 		     diff_index_cached,
-		     debug_unpack,
 		     skip_sparse_checkout,
 		     quiet,
 		     exiting_early,
@@ -78,7 +77,6 @@ struct unpack_trees_options {
 	merge_fn_t fn;
 
 	int head_idx;
-	int merge_size;
 
 	struct cache_entry *df_conflict_entry;
 	void *unpack_data;
@@ -90,8 +88,10 @@ struct unpack_trees_options {
 
 	struct unpack_trees_options_internal {
 		unsigned int nontrivial_merge,
-			     show_all_errors;
+			     show_all_errors,
+			     debug_unpack; /* used by read-tree debugging */
 
+		int merge_size; /* used by read-tree debugging */
 		int cache_bottom;
 		const char *msgs[NB_UNPACK_TREES_WARNING_TYPES];
 		struct strvec msgs_to_free;
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 19 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.