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

[PATCH 52/53] tree: convert parse_tree_indirect to struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 23, 2017, 21:34 UTC
Message-ID
<20170423213453.253425-53-sandals@crustytoothpaste.net>
In-Reply-To
<20170423213453.253425-1-sandals@crustytoothpaste.net>

Convert parse_tree_indirect to take a pointer to struct object_id. Update all the callers. This transformation was achieved using the following semantic patch and manual updates to the declaration and definition. Update builtin/checkout.c manually as well, since it uses a ternary expression not handled by the semantic patch.

@@
expression E1;
@@
- parse_tree_indirect(E1.hash)
+ parse_tree_indirect(&E1)
@@
expression E1;
@@
- parse_tree_indirect(E1->hash)
+ parse_tree_indirect(E1)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 archive.c                   | 4 ++--
 builtin/am.c                | 6 +++---
 builtin/checkout.c          | 8 ++++----
 builtin/clone.c             | 2 +-
 builtin/commit.c            | 2 +-
 builtin/ls-files.c          | 2 +-
 builtin/ls-tree.c           | 2 +-
 builtin/merge.c             | 6 +++---
 builtin/read-tree.c         | 2 +-
 builtin/reset.c             | 4 ++--
 diff-lib.c                  | 2 +-
 merge.c                     | 4 ++--
 sequencer.c                 | 2 +-
 t/helper/test-match-trees.c | 4 ++--
 tree.c                      | 4 ++--
 tree.h                      | 2 +-
 16 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/archive.c b/archive.c
index 54701e8bb..b15a922da 100644
--- a/archive.c
+++ b/archive.c
@@ -369,7 +369,7 @@ static void parse_treeish_arg(const char **argv,
 		archive_time = time(NULL);
 	}
 
-	tree = parse_tree_indirect(oid.hash);
+	tree = parse_tree_indirect(&oid);
 	if (tree == NULL)
 		die("not a tree object");
 
@@ -383,7 +383,7 @@ static void parse_treeish_arg(const char **argv,
 		if (err || !S_ISDIR(mode))
 			die("current working directory is untracked");
 
-		tree = parse_tree_indirect(tree_oid.hash);
+		tree = parse_tree_indirect(&tree_oid);
 	}
 	ar_args->tree = tree;
 	ar_args->commit_sha1 = commit_sha1;
diff --git a/builtin/am.c b/builtin/am.c
index 210ecc554..c21059e6e 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2046,11 +2046,11 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
 	struct tree *head_tree, *remote_tree, *index_tree;
 	struct object_id index;
 
-	head_tree = parse_tree_indirect(head->hash);
+	head_tree = parse_tree_indirect(head);
 	if (!head_tree)
 		return error(_("Could not parse object '%s'."), oid_to_hex(head));
 
-	remote_tree = parse_tree_indirect(remote->hash);
+	remote_tree = parse_tree_indirect(remote);
 	if (!remote_tree)
 		return error(_("Could not parse object '%s'."), oid_to_hex(remote));
 
@@ -2062,7 +2062,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
 	if (write_cache_as_tree(index.hash, 0, NULL))
 		return -1;
 
-	index_tree = parse_tree_indirect(index.hash);
+	index_tree = parse_tree_indirect(&index);
 	if (!index_tree)
 		return error(_("Could not parse object '%s'."), oid_to_hex(&index));
 
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 7f1eeea94..13365fb62 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			setup_standard_excludes(topts.dir);
 		}
 		tree = parse_tree_indirect(old->commit ?
-					   old->commit->object.oid.hash :
-					   EMPTY_TREE_SHA1_BIN);
+					   &old->commit->object.oid :
+					   &empty_tree_oid);
 		init_tree_desc(&trees[0], tree->buffer, tree->size);
-		tree = parse_tree_indirect(new->commit->object.oid.hash);
+		tree = parse_tree_indirect(&new->commit->object.oid);
 		init_tree_desc(&trees[1], tree->buffer, tree->size);
 
 		ret = unpack_trees(2, trees, &topts);
@@ -1050,7 +1050,7 @@ static int parse_branchname_arg(int argc, const char **argv,
 	new->commit = lookup_commit_reference_gently(rev, 1);
 	if (!new->commit) {
 		/* not a commit */
-		*source_tree = parse_tree_indirect(rev->hash);
+		*source_tree = parse_tree_indirect(rev);
 	} else {
 		parse_commit_or_die(new->commit);
 		*source_tree = new->commit->tree;
diff --git a/builtin/clone.c b/builtin/clone.c
index 646f28792..da2d3c1ae 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -739,7 +739,7 @@ static int checkout(int submodule_progress)
 	opts.src_index = &the_index;
 	opts.dst_index = &the_index;
 
-	tree = parse_tree_indirect(oid.hash);
+	tree = parse_tree_indirect(&oid);
 	parse_tree(tree);
 	init_tree_desc(&t, tree->buffer, tree->size);
 	if (unpack_trees(1, &t, &opts) < 0)
diff --git a/builtin/commit.c b/builtin/commit.c
index d349d48ef..1d625e49e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -313,7 +313,7 @@ static void create_base_index(const struct commit *current_head)
 	opts.dst_index = &the_index;
 
 	opts.fn = oneway_merge;
-	tree = parse_tree_indirect(current_head->object.oid.hash);
+	tree = parse_tree_indirect(&current_head->object.oid);
 	if (!tree)
 		die(_("failed to unpack HEAD tree object"));
 	parse_tree(tree);
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 948c7066c..cac802ff9 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -414,7 +414,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
 
 	if (get_oid(tree_name, &oid))
 		die("tree-ish %s not found.", tree_name);
-	tree = parse_tree_indirect(oid.hash);
+	tree = parse_tree_indirect(&oid);
 	if (!tree)
 		die("bad tree-ish %s", tree_name);
 
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 5baac3ef2..ee7b293b1 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -180,7 +180,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
 	for (i = 0; i < pathspec.nr; i++)
 		pathspec.items[i].nowildcard_len = pathspec.items[i].len;
 	pathspec.has_wildcard = 0;
-	tree = parse_tree_indirect(oid.hash);
+	tree = parse_tree_indirect(&oid);
 	if (!tree)
 		die("not a tree object");
 	return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
diff --git a/builtin/merge.c b/builtin/merge.c
index 5ea7f7da9..a4a098f40 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -605,13 +605,13 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
 	opts.verbose_update = 1;
 	opts.trivial_merges_only = 1;
 	opts.merge = 1;
-	trees[nr_trees] = parse_tree_indirect(common->hash);
+	trees[nr_trees] = parse_tree_indirect(common);
 	if (!trees[nr_trees++])
 		return -1;
-	trees[nr_trees] = parse_tree_indirect(head->hash);
+	trees[nr_trees] = parse_tree_indirect(head);
 	if (!trees[nr_trees++])
 		return -1;
-	trees[nr_trees] = parse_tree_indirect(one->hash);
+	trees[nr_trees] = parse_tree_indirect(one);
 	if (!trees[nr_trees++])
 		return -1;
 	opts.fn = threeway_merge;
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 92eff23e4..6d45175f6 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -29,7 +29,7 @@ static int list_tree(struct object_id *oid)
 
 	if (nr_trees >= MAX_UNPACK_TREES)
 		die("I cannot read more than %d trees", MAX_UNPACK_TREES);
-	tree = parse_tree_indirect(oid->hash);
+	tree = parse_tree_indirect(oid);
 	if (!tree)
 		return -1;
 	trees[nr_trees++] = tree;
diff --git a/builtin/reset.c b/builtin/reset.c
index 3415dac5d..c782739c2 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -84,7 +84,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
 		return -1;
 
 	if (reset_type == MIXED || reset_type == HARD) {
-		tree = parse_tree_indirect(oid->hash);
+		tree = parse_tree_indirect(oid);
 		prime_cache_tree(&the_index, tree);
 	}
 
@@ -311,7 +311,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		struct tree *tree;
 		if (get_sha1_treeish(rev, oid.hash))
 			die(_("Failed to resolve '%s' as a valid tree."), rev);
-		tree = parse_tree_indirect(oid.hash);
+		tree = parse_tree_indirect(&oid);
 		if (!tree)
 			die(_("Could not parse object '%s'."), rev);
 		oidcpy(&oid, &tree->object.oid);
diff --git a/diff-lib.c b/diff-lib.c
index ee9df0f84..2982bf055 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -486,7 +486,7 @@ static int diff_cache(struct rev_info *revs,
 	struct tree_desc t;
 	struct unpack_trees_options opts;
 
-	tree = parse_tree_indirect(tree_oid->hash);
+	tree = parse_tree_indirect(tree_oid);
 	if (!tree)
 		return error("bad tree object %s",
 			     tree_name ? tree_name : oid_to_hex(tree_oid));
diff --git a/merge.c b/merge.c
index b0cffe16f..1d441ad94 100644
--- a/merge.c
+++ b/merge.c
@@ -79,10 +79,10 @@ int checkout_fast_forward(const struct object_id *head,
 	opts.fn = twoway_merge;
 	setup_unpack_trees_porcelain(&opts, "merge");
 
-	trees[nr_trees] = parse_tree_indirect(head->hash);
+	trees[nr_trees] = parse_tree_indirect(head);
 	if (!trees[nr_trees++])
 		return -1;
-	trees[nr_trees] = parse_tree_indirect(remote->hash);
+	trees[nr_trees] = parse_tree_indirect(remote);
 	if (!trees[nr_trees++])
 		return -1;
 	for (i = 0; i < nr_trees; i++) {
diff --git a/sequencer.c b/sequencer.c
index ed48c4c29..a2aa77f46 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -446,7 +446,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
 	if (is_rebase_i(opts))
 		o.buffer_output = 2;
 
-	head_tree = parse_tree_indirect(head->hash);
+	head_tree = parse_tree_indirect(head);
 	next_tree = next ? next->tree : empty_tree();
 	base_tree = base ? base->tree : empty_tree();
 
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index e93950286..356d8edef 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -12,10 +12,10 @@ int cmd_main(int ac, const char **av)
 		die("cannot parse %s as an object name", av[1]);
 	if (get_oid(av[2], &hash2))
 		die("cannot parse %s as an object name", av[2]);
-	one = parse_tree_indirect(hash1.hash);
+	one = parse_tree_indirect(&hash1);
 	if (!one)
 		die("not a tree-ish %s", av[1]);
-	two = parse_tree_indirect(hash2.hash);
+	two = parse_tree_indirect(&hash2);
 	if (!two)
 		die("not a tree-ish %s", av[2]);
 
diff --git a/tree.c b/tree.c
index 28ce930b9..9adcd8bd4 100644
--- a/tree.c
+++ b/tree.c
@@ -232,9 +232,9 @@ void free_tree_buffer(struct tree *tree)
 	tree->object.parsed = 0;
 }
 
-struct tree *parse_tree_indirect(const unsigned char *sha1)
+struct tree *parse_tree_indirect(const struct object_id *oid)
 {
-	struct object *obj = parse_object(sha1);
+	struct object *obj = parse_object(oid->hash);
 	do {
 		if (!obj)
 			return NULL;
diff --git a/tree.h b/tree.h
index 2b2c8dbbe..0d4734b94 100644
--- a/tree.h
+++ b/tree.h
@@ -24,7 +24,7 @@ static inline int parse_tree(struct tree *tree)
 void free_tree_buffer(struct tree *tree);
 
 /* Parses and returns the tree in the given ent, chasing tags and commits. */
-struct tree *parse_tree_indirect(const unsigned char *sha1);
+struct tree *parse_tree_indirect(const struct object_id *oid);
 
 #define READ_TREE_RECURSIVE 1
 typedef int (*read_tree_fn_t)(const unsigned char *, struct strbuf *, const char *, unsigned int, int, void *);
Previous: brian m. carlsonNext: brian m. carlson
Message 63 of 67 in “object_id part 8”
  1. 00/53 object_id part 8brian m. carlson, Apr 23, 2017
  2. 02/53 Clean up outstanding object_id transforms.brian m. carlson, Apr 23, 2017
  3. 01/53 fetch-pack: convert to struct object_idbrian m. carlson, Apr 23, 2017
  4. 03/53 Convert struct cache_tree to use struct object_idbrian m. carlson, Apr 23, 2017
  5. 04/53 builtin/name-rev: convert to struct object_idbrian m. carlson, Apr 23, 2017
  6. 05/53 builtin/prune: convert to struct object_idbrian m. carlson, Apr 23, 2017
  7. 06/53 bundle: convert to struct object_idbrian m. carlson, Apr 23, 2017
  8. 08/53 builtin/blame: convert static function to struct object_idbrian m. carlson, Apr 23, 2017
  9. 07/53 branch: convert to struct object_idbrian m. carlson, Apr 23, 2017
  10. 10/53 fast-import: convert internal structs to struct object_idbrian m. carlson, Apr 23, 2017
  11. 09/53 builtin/rev-parse: convert to struct object_idbrian m. carlson, Apr 23, 2017
  12. 12/53 submodule: convert merge_submodule to use struct object_idbrian m. carlson, Apr 23, 2017
  13. 13/53 notes-cache: convert to struct object_idbrian m. carlson, Apr 23, 2017
  14. Stefan BellerApr 24, 2017
  15. 11/53 fast-import: convert to struct object_idbrian m. carlson, Apr 23, 2017
  16. Stefan BellerApr 24, 2017
  17. brian m. carlsonApr 24, 2017
  18. 14/53 parse-options-cb: convert to struct object_idbrian m. carlson, Apr 23, 2017
  19. 17/53 tag: convert parse_tag_buffer to struct object_idbrian m. carlson, Apr 23, 2017
  20. 15/53 reflog_expire: convert to struct object_idbrian m. carlson, Apr 23, 2017
  21. 16/53 builtin/verify-commit: convert to struct object_idbrian m. carlson, Apr 23, 2017
  22. 19/53 notes-utils: convert internals to struct object_idbrian m. carlson, Apr 23, 2017
  23. 18/53 http-push: convert some static functions to struct object_idbrian m. carlson, Apr 23, 2017
  24. 22/53 sequencer: convert some functions to struct object_idbrian m. carlson, Apr 23, 2017
  25. 20/53 revision: convert prepare_show_merge to struct object_idbrian m. carlson, Apr 23, 2017
  26. 21/53 shallow: convert shallow registration functions to object_idbrian m. carlson, Apr 23, 2017
  27. 23/53 builtin/tag: convert to struct object_idbrian m. carlson, Apr 23, 2017
  28. 24/53 Convert remaining callers of lookup_commit_reference* to object_idbrian m. carlson, Apr 23, 2017
  29. 26/53 pack: convert struct pack_idx_entry to struct object_idbrian m. carlson, Apr 23, 2017
  30. 25/53 Convert lookup_commit* to struct object_idbrian m. carlson, Apr 23, 2017
  31. 27/53 builtin/unpack-objects: convert to struct object_idbrian m. carlson, Apr 23, 2017
  32. 28/53 Convert remaining callers of lookup_blob to object_idbrian m. carlson, Apr 23, 2017
  33. Stefan BellerApr 24, 2017
  34. 29/53 Convert lookup_blob to struct object_idbrian m. carlson, Apr 23, 2017
  35. 30/53 tree: convert read_tree_1 to use struct object_id internallybrian m. carlson, Apr 23, 2017
  36. 31/53 builtin/reflog: convert tree_is_complete to take struct object_idbrian m. carlson, Apr 23, 2017
  37. 34/53 Convert lookup_tag to struct object_idbrian m. carlson, Apr 23, 2017
  38. 32/53 Convert lookup_tree to struct object_idbrian m. carlson, Apr 23, 2017
  39. 33/53 log-tree: convert to struct object_idbrian m. carlson, Apr 23, 2017
  40. 35/53 Convert the verify_pack callback to struct object_idbrian m. carlson, Apr 23, 2017
  41. Stefan BellerApr 26, 2017
  42. Jeff KingApr 27, 2017
  43. brian m. carlsonApr 28, 2017
  44. Jeff KingApr 28, 2017
  45. 36/53 Convert struct ref_array_item to struct object_idbrian m. carlson, Apr 23, 2017
  46. 37/53 ref-filter: convert some static functions to struct object_idbrian m. carlson, Apr 23, 2017
  47. 38/53 refs: convert struct ref_update to use struct object_idbrian m. carlson, Apr 23, 2017
  48. Michael HaggertyApr 27, 2017
  49. 39/53 refs/files-backend: convert many internals to struct object_idbrian m. carlson, Apr 23, 2017
  50. Michael HaggertyApr 27, 2017
  51. 40/53 http-push: convert process_ls_object and descendants to object_idbrian m. carlson, Apr 23, 2017
  52. 41/53 revision: rename add_pending_sha1 to add_pending_oidbrian m. carlson, Apr 23, 2017
  53. 43/53 upload-pack: convert remaining parse_object callers to object_idbrian m. carlson, Apr 23, 2017
  54. 46/53 builtin/ls-files: convert overlay_tree_on_cache to object_idbrian m. carlson, Apr 23, 2017
  55. 45/53 builtin/read-tree: convert to struct object_idbrian m. carlson, Apr 23, 2017
  56. 47/53 sequencer: convert fast_forward_to to struct object_idbrian m. carlson, Apr 23, 2017
  57. 51/53 sequencer: convert do_recursive_merge to struct object_idbrian m. carlson, Apr 23, 2017
  58. 50/53 diff-lib: convert do_diff_cache to struct object_idbrian m. carlson, Apr 23, 2017
  59. 48/53 merge: convert checkout_fast_forward to struct object_idbrian m. carlson, Apr 23, 2017
  60. 49/53 builtin/ls-tree: convert to struct object_idbrian m. carlson, Apr 23, 2017
  61. 44/53 sha1_name: convert internals of peel_onion to object_idbrian m. carlson, Apr 23, 2017
  62. 42/53 revision: convert remaining parse_object callers to object_idbrian m. carlson, Apr 23, 2017
  63. 52/53 tree: convert parse_tree_indirect to struct object_idbrian m. carlson, Apr 23, 2017
  64. 53/53 object: convert parse_object* to take struct object_idbrian m. carlson, Apr 23, 2017
  65. Stefan BellerApr 27, 2017
  66. Junio C HamanoApr 24, 2017
  67. Brandon WilliamsApr 24, 2017

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.