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

[PATCH v2 8/8] merge-recursive: convert merge_recursive_generic to object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 18, 2016, 22:14 UTC
Message-ID
<20160618221407.1046188-9-sandals@crustytoothpaste.net>
In-Reply-To
<20160618221407.1046188-1-sandals@crustytoothpaste.net>

Convert this function and the git merge-recursive subcommand to use struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/merge-recursive.c | 20 ++++++++++----------
 merge-recursive.c         | 14 +++++++-------
 merge-recursive.h         |  6 +++---
 3 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index 491efd55..fd2c4556 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -9,10 +9,10 @@ static const char builtin_merge_recursive_usage[] =
 
 static const char *better_branch_name(const char *branch)
 {
-	static char githead_env[8 + 40 + 1];
+	static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
 	char *name;
 
-	if (strlen(branch) != 40)
+	if (strlen(branch) != GIT_SHA1_HEXSZ)
 		return branch;
 	xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
 	name = getenv(githead_env);
@@ -21,10 +21,10 @@ static const char *better_branch_name(const char *branch)
 
 int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
 {
-	const unsigned char *bases[21];
+	const struct object_id *bases[21];
 	unsigned bases_count = 0;
 	int i, failed;
-	unsigned char h1[20], h2[20];
+	struct object_id h1, h2;
 	struct merge_options o;
 	struct commit *result;
 
@@ -46,10 +46,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (bases_count < ARRAY_SIZE(bases)-1) {
-			unsigned char *sha = xmalloc(20);
-			if (get_sha1(argv[i], sha))
+			struct object_id *oid = xmalloc(sizeof(struct object_id));
+			if (get_oid(argv[i], oid))
 				die("Could not parse object '%s'", argv[i]);
-			bases[bases_count++] = sha;
+			bases[bases_count++] = oid;
 		}
 		else
 			warning("Cannot handle more than %d bases. "
@@ -62,9 +62,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
 	o.branch1 = argv[++i];
 	o.branch2 = argv[++i];
 
-	if (get_sha1(o.branch1, h1))
+	if (get_oid(o.branch1, &h1))
 		die("Could not resolve ref '%s'", o.branch1);
-	if (get_sha1(o.branch2, h2))
+	if (get_oid(o.branch2, &h2))
 		die("Could not resolve ref '%s'", o.branch2);
 
 	o.branch1 = better_branch_name(o.branch1);
@@ -73,7 +73,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
 	if (o.verbosity >= 3)
 		printf("Merging %s with %s\n", o.branch1, o.branch2);
 
-	failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result);
+	failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
 	if (failed < 0)
 		return 128; /* die() error code */
 	return failed;
diff --git a/merge-recursive.c b/merge-recursive.c
index 7bbd4aea..48fe7e73 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1982,11 +1982,11 @@ int merge_recursive(struct merge_options *o,
 	return clean;
 }
 
-static struct commit *get_ref(const unsigned char *sha1, const char *name)
+static struct commit *get_ref(const struct object_id *oid, const char *name)
 {
 	struct object *object;
 
-	object = deref_tag(parse_object(sha1), name, strlen(name));
+	object = deref_tag(parse_object(oid->hash), name, strlen(name));
 	if (!object)
 		return NULL;
 	if (object->type == OBJ_TREE)
@@ -1999,10 +1999,10 @@ static struct commit *get_ref(const unsigned char *sha1, const char *name)
 }
 
 int merge_recursive_generic(struct merge_options *o,
-			    const unsigned char *head,
-			    const unsigned char *merge,
+			    const struct object_id *head,
+			    const struct object_id *merge,
 			    int num_base_list,
-			    const unsigned char **base_list,
+			    const struct object_id **base_list,
 			    struct commit **result)
 {
 	int clean;
@@ -2015,9 +2015,9 @@ int merge_recursive_generic(struct merge_options *o,
 		int i;
 		for (i = 0; i < num_base_list; ++i) {
 			struct commit *base;
-			if (!(base = get_ref(base_list[i], sha1_to_hex(base_list[i]))))
+			if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))
 				return error(_("Could not parse object '%s'"),
-					sha1_to_hex(base_list[i]));
+					oid_to_hex(base_list[i]));
 			commit_list_insert(base, &ca);
 		}
 	}
diff --git a/merge-recursive.h b/merge-recursive.h
index 52f0201f..d415724a 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -49,10 +49,10 @@ int merge_trees(struct merge_options *o,
  * virtual commits and call merge_recursive() proper.
  */
 int merge_recursive_generic(struct merge_options *o,
-			    const unsigned char *head,
-			    const unsigned char *merge,
+			    const struct object_id *head,
+			    const struct object_id *merge,
 			    int num_ca,
-			    const unsigned char **ca,
+			    const struct object_id **ca,
 			    struct commit **result);
 
 void init_merge_options(struct merge_options *o);
Previous: Junio C HamanoNext: brian m. carlson
Message 6 of 20 in “object_id part 4”
  1. 0/8 object_id part 4brian m. carlson, Jun 18, 2016
  2. 6/8 merge-recursive: convert struct merge_file_info to object_idbrian m. carlson, Jun 18, 2016
  3. 4/8 Rename struct diff_filespec's sha1_valid member.brian m. carlson, Jun 18, 2016
  4. 2/8 Apply object_id Coccinelle transformations.brian m. carlson, Jun 18, 2016
  5. Junio C HamanoJun 21, 2016
  6. 8/8 merge-recursive: convert merge_recursive_generic to object_idbrian m. carlson, Jun 18, 2016
  7. 7/8 merge-recursive: convert leaf functions to use struct object_idbrian m. carlson, Jun 18, 2016
  8. 5/8 merge-recursive: convert struct stage_data to use object_idbrian m. carlson, Jun 18, 2016
  9. 3/8 Convert struct diff_filespec to struct object_idbrian m. carlson, Jun 18, 2016
  10. Junio C HamanoJun 21, 2016
  11. brian m. carlsonJun 24, 2016
  12. 1/8 Add basic Coccinelle transforms.brian m. carlson, Jun 18, 2016
  13. Johannes SixtJun 19, 2016
  14. Jeff KingJun 19, 2016
  15. brian m. carlsonJun 19, 2016
  16. Johannes SchindelinJun 20, 2016
  17. Jeff KingJun 20, 2016
  18. Junio C HamanoJun 20, 2016
  19. Junio C HamanoJun 21, 2016
  20. brian m. carlsonJun 22, 2016

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.