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

[PATCH 3/6] Make reset_tree() in builtin-checkout.c a bit more library-ish

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 6, 2008, 01:54 UTC
Message-ID
<1228528455-3089-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1228528455-3089-3-git-send-email-gitster@pobox.com>

The function demanded an internal structure "struct checkout_opts" as its argument, but we'd want to split this (and one of its callers) out into a separate library. This makes what the function wants a bit more explicit and much less dependent on the rest of builtin-checkout.c

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-checkout.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index c2c0561..d88fce2 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -319,7 +319,7 @@ static void describe_detached_head(char *msg, struct commit *commit)
 	strbuf_release(&sb);
 }
 
-static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
+static int reset_tree(struct tree *tree, int quiet, int worktree, int *wt_error)
 {
 	struct unpack_trees_options opts;
 	struct tree_desc tree_desc;
@@ -331,14 +331,14 @@ static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
 	opts.reset = 1;
 	opts.merge = 1;
 	opts.fn = oneway_merge;
-	opts.verbose_update = !o->quiet;
+	opts.verbose_update = !quiet;
 	opts.src_index = &the_index;
 	opts.dst_index = &the_index;
 	parse_tree(tree);
 	init_tree_desc(&tree_desc, tree->buffer, tree->size);
 	switch (unpack_trees(1, &tree_desc, &opts)) {
 	case -2:
-		o->writeout_error = 1;
+		*wt_error = 1;
 		/*
 		 * We return 0 nevertheless, as the index is all right
 		 * and more importantly we have made best efforts to
@@ -377,7 +377,8 @@ static int merge_working_tree(struct checkout_opts *opts,
 		return error("corrupt index file");
 
 	if (opts->force) {
-		ret = reset_tree(new->commit->tree, opts, 1);
+		ret = reset_tree(new->commit->tree, opts->quiet, 1,
+				 &opts->writeout_error);
 		if (ret)
 			return ret;
 	} else {
@@ -446,14 +447,16 @@ static int merge_working_tree(struct checkout_opts *opts,
 			o.verbosity = 0;
 			work = write_tree_from_memory(&o);
 
-			ret = reset_tree(new->commit->tree, opts, 1);
+			ret = reset_tree(new->commit->tree, opts->quiet, 1,
+					 &opts->writeout_error);
 			if (ret)
 				return ret;
 			o.branch1 = new->name;
 			o.branch2 = "local";
 			merge_trees(&o, new->commit->tree, work,
 				old->commit->tree, &result);
-			ret = reset_tree(new->commit->tree, opts, 0);
+			ret = reset_tree(new->commit->tree, opts->quiet, 0,
+					 &opts->writeout_error);
 			if (ret)
 				return ret;
 		}
-- 
1.6.1.rc1.72.ga5ce6
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 8 in “Reusing "checkout [-m]" logic for "reset --merge"”
  1. 0/6 Reusing "checkout [-m]" logic for "reset --merge"Junio C Hamano, Dec 6, 2008
  2. 1/6 builtin-checkout.c: check error return from read_cache()Junio C Hamano, Dec 6, 2008
  3. 2/6 read-cache.c: typofix in commentJunio C Hamano, Dec 6, 2008
  4. 3/6 Make reset_tree() in builtin-checkout.c a bit more library-ishJunio C Hamano, Dec 6, 2008
  5. 4/6 builtin-checkout.c: refactor merge_working_tree()Junio C Hamano, Dec 6, 2008
  6. 5/6 builtin-commit.c: further refactor branch switchingJunio C Hamano, Dec 6, 2008
  7. 6/6 builtin-reset.c: use reset_index_and_worktree()Junio C Hamano, Dec 6, 2008
  8. Linus TorvaldsDec 6, 2008

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.