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

[PATCH 09/53] builtin/rev-parse: convert to struct object_id

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

Some of the functions converted are callers of lookup_commit_reference. However, the changes involved in converting the entire thing are not too large, so we might as well convert it all.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/rev-parse.c | 56 ++++++++++++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 051333091..272bb13a0 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -121,7 +121,7 @@ static void show_with_type(int type, const char *arg)
 }
 
 /* Output a revision, only if filter allows it */
-static void show_rev(int type, const unsigned char *sha1, const char *name)
+static void show_rev(int type, const struct object_id *oid, const char *name)
 {
 	if (!(filter & DO_REVS))
 		return;
@@ -129,10 +129,10 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
 
 	if ((symbolic || abbrev_ref) && name) {
 		if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
-			unsigned char discard[20];
+			struct object_id discard;
 			char *full;
 
-			switch (dwim_ref(name, strlen(name), discard, &full)) {
+			switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
 			case 0:
 				/*
 				 * Not found -- not a ref.  We could
@@ -158,9 +158,9 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
 		}
 	}
 	else if (abbrev)
-		show_with_type(type, find_unique_abbrev(sha1, abbrev));
+		show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
 	else
-		show_with_type(type, sha1_to_hex(sha1));
+		show_with_type(type, oid_to_hex(oid));
 }
 
 /* Output a flag, only if filter allows it. */
@@ -180,11 +180,11 @@ static int show_default(void)
 	const char *s = def;
 
 	if (s) {
-		unsigned char sha1[20];
+		struct object_id oid;
 
 		def = NULL;
-		if (!get_sha1(s, sha1)) {
-			show_rev(NORMAL, sha1, s);
+		if (!get_oid(s, &oid)) {
+			show_rev(NORMAL, &oid, s);
 			return 1;
 		}
 	}
@@ -195,19 +195,19 @@ static int show_reference(const char *refname, const struct object_id *oid, int
 {
 	if (ref_excluded(ref_excludes, refname))
 		return 0;
-	show_rev(NORMAL, oid->hash, refname);
+	show_rev(NORMAL, oid, refname);
 	return 0;
 }
 
 static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)
 {
-	show_rev(REVERSED, oid->hash, refname);
+	show_rev(REVERSED, oid, refname);
 	return 0;
 }
 
 static int show_abbrev(const struct object_id *oid, void *cb_data)
 {
-	show_rev(NORMAL, oid->hash, NULL);
+	show_rev(NORMAL, oid, NULL);
 	return 0;
 }
 
@@ -242,8 +242,8 @@ static int show_file(const char *arg, int output_prefix)
 static int try_difference(const char *arg)
 {
 	char *dotdot;
-	unsigned char sha1[20];
-	unsigned char end[20];
+	struct object_id oid;
+	struct object_id end;
 	const char *next;
 	const char *this;
 	int symmetric;
@@ -273,18 +273,18 @@ static int try_difference(const char *arg)
 		return 0;
 	}
 
-	if (!get_sha1_committish(this, sha1) && !get_sha1_committish(next, end)) {
-		show_rev(NORMAL, end, next);
-		show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
+	if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) {
+		show_rev(NORMAL, &end, next);
+		show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
 		if (symmetric) {
 			struct commit_list *exclude;
 			struct commit *a, *b;
-			a = lookup_commit_reference(sha1);
-			b = lookup_commit_reference(end);
+			a = lookup_commit_reference(oid.hash);
+			b = lookup_commit_reference(end.hash);
 			exclude = get_merge_bases(a, b);
 			while (exclude) {
 				struct commit *commit = pop_commit(&exclude);
-				show_rev(REVERSED, commit->object.oid.hash, NULL);
+				show_rev(REVERSED, &commit->object.oid, NULL);
 			}
 		}
 		*dotdot = '.';
@@ -297,7 +297,7 @@ static int try_difference(const char *arg)
 static int try_parent_shorthands(const char *arg)
 {
 	char *dotdot;
-	unsigned char sha1[20];
+	struct object_id oid;
 	struct commit *commit;
 	struct commit_list *parents;
 	int parent_number;
@@ -327,12 +327,12 @@ static int try_parent_shorthands(const char *arg)
 		return 0;
 
 	*dotdot = 0;
-	if (get_sha1_committish(arg, sha1)) {
+	if (get_sha1_committish(arg, oid.hash)) {
 		*dotdot = '^';
 		return 0;
 	}
 
-	commit = lookup_commit_reference(sha1);
+	commit = lookup_commit_reference(oid.hash);
 	if (exclude_parent &&
 	    exclude_parent > commit_list_count(commit->parents)) {
 		*dotdot = '^';
@@ -340,7 +340,7 @@ static int try_parent_shorthands(const char *arg)
 	}
 
 	if (include_rev)
-		show_rev(NORMAL, sha1, arg);
+		show_rev(NORMAL, &oid, arg);
 	for (parents = commit->parents, parent_number = 1;
 	     parents;
 	     parents = parents->next, parent_number++) {
@@ -352,7 +352,7 @@ static int try_parent_shorthands(const char *arg)
 		if (symbolic)
 			name = xstrfmt("%s^%d", arg, parent_number);
 		show_rev(include_parents ? NORMAL : REVERSED,
-			 parents->item->object.oid.hash, name);
+			& parents->item->object.oid, name);
 		free(name);
 	}
 
@@ -571,7 +571,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 	int did_repo_setup = 0;
 	int has_dashdash = 0;
 	int output_prefix = 0;
-	unsigned char sha1[20];
+	struct object_id oid;
 	unsigned int flags = 0;
 	const char *name = NULL;
 	struct object_context unused;
@@ -910,11 +910,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 			name++;
 			type = REVERSED;
 		}
-		if (!get_sha1_with_context(name, flags, sha1, &unused)) {
+		if (!get_sha1_with_context(name, flags, oid.hash, &unused)) {
 			if (verify)
 				revs_count++;
 			else
-				show_rev(type, sha1, name);
+				show_rev(type, &oid, name);
 			continue;
 		}
 		if (verify)
@@ -929,7 +929,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 	strbuf_release(&buf);
 	if (verify) {
 		if (revs_count == 1) {
-			show_rev(type, sha1, name);
+			show_rev(type, &oid, name);
 			return 0;
 		} else if (revs_count == 0 && show_default())
 			return 0;
Previous: brian m. carlsonNext: brian m. carlson
Message 11 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.