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

[PATCH v3 22/36] sha1_file: convert assert_sha1_type to object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Mar 12, 2018, 02:27 UTC
Message-ID
<20180312022756.483934-23-sandals@crustytoothpaste.net>
In-Reply-To
<20180312022756.483934-1-sandals@crustytoothpaste.net>

Convert this function to take a pointer to struct object_id and rename it to assert_oid_type.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/commit-tree.c | 2 +-
 cache.h               | 2 +-
 commit.c              | 2 +-
 sha1_file.c           | 8 ++++----
 4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index e5bdf57b1e..ecf42191da 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 				usage(commit_tree_usage);
 			if (get_oid_commit(argv[i], &oid))
 				die("Not a valid object name %s", argv[i]);
-			assert_sha1_type(oid.hash, OBJ_COMMIT);
+			assert_oid_type(&oid, OBJ_COMMIT);
 			new_parent(lookup_commit(&oid), &parents);
 			continue;
 		}
diff --git a/cache.h b/cache.h
index 27b5fd8a39..67a04fcd12 100644
--- a/cache.h
+++ b/cache.h
@@ -1275,7 +1275,7 @@ extern int has_object_file_with_flags(const struct object_id *oid, int flags);
  */
 extern int has_loose_object_nonlocal(const unsigned char *sha1);
 
-extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);
+extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
 
 /* Helper to check and "touch" a file */
 extern int check_and_freshen_file(const char *fn, int freshen);
diff --git a/commit.c b/commit.c
index 00c99c7272..6d77787af9 100644
--- a/commit.c
+++ b/commit.c
@@ -1517,7 +1517,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 	int encoding_is_utf8;
 	struct strbuf buffer;
 
-	assert_sha1_type(tree->hash, OBJ_TREE);
+	assert_oid_type(tree, OBJ_TREE);
 
 	if (memchr(msg, '\0', msg_len))
 		return error("a NUL byte in commit log message not allowed.");
diff --git a/sha1_file.c b/sha1_file.c
index cdcba4483b..a307037e88 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1966,13 +1966,13 @@ int read_pack_header(int fd, struct pack_header *header)
 	return 0;
 }
 
-void assert_sha1_type(const unsigned char *sha1, enum object_type expect)
+void assert_oid_type(const struct object_id *oid, enum object_type expect)
 {
-	enum object_type type = sha1_object_info(sha1, NULL);
+	enum object_type type = sha1_object_info(oid->hash, NULL);
 	if (type < 0)
-		die("%s is not a valid object", sha1_to_hex(sha1));
+		die("%s is not a valid object", oid_to_hex(oid));
 	if (type != expect)
-		die("%s is not a valid '%s' object", sha1_to_hex(sha1),
+		die("%s is not a valid '%s' object", oid_to_hex(oid),
 		    type_name(expect));
 }
 
Previous: brian m. carlsonNext: brian m. carlson
Message 11 of 42 in “object_id part 12”
  1. 00/36 object_id part 12brian m. carlson, Mar 12, 2018
  2. 01/36 bulk-checkin: convert index_bulk_checkin to struct object_idbrian m. carlson, Mar 12, 2018
  3. 03/36 cache-tree: convert write_*_as_tree to object_idbrian m. carlson, Mar 12, 2018
  4. 04/36 cache-tree: convert remnants to struct object_idbrian m. carlson, Mar 12, 2018
  5. 06/36 tree: convert read_tree_recursive to struct object_idbrian m. carlson, Mar 12, 2018
  6. 08/36 strbuf: convert strbuf_add_unique_abbrev to use struct object_idbrian m. carlson, Mar 12, 2018
  7. 07/36 ref-filter: convert grab_objectname to struct object_idbrian m. carlson, Mar 12, 2018
  8. 13/36 replace_object: convert struct replace_object to object_idbrian m. carlson, Mar 12, 2018
  9. 16/36 archive: convert sha1_file_to_archive to struct object_idbrian m. carlson, Mar 12, 2018
  10. 20/36 streaming: convert open_istream to use struct object_idbrian m. carlson, Mar 12, 2018
  11. 22/36 sha1_file: convert assert_sha1_type to object_idbrian m. carlson, Mar 12, 2018
  12. 23/36 sha1_file: convert retry_bad_packed_offset to struct object_idbrian m. carlson, Mar 12, 2018
  13. 25/36 Convert remaining callers of sha1_object_info_extended to object_idbrian m. carlson, Mar 12, 2018
  14. 27/36 builtin/fmt-merge-msg: convert remaining code to object_idbrian m. carlson, Mar 12, 2018
  15. 30/36 streaming: convert istream internals to struct object_idbrian m. carlson, Mar 12, 2018
  16. 26/36 sha1_file: convert sha1_object_info* to object_idbrian m. carlson, Mar 12, 2018
  17. 28/36 builtin/notes: convert static functions to object_idbrian m. carlson, Mar 12, 2018
  18. 34/36 Convert lookup_replace_object to struct object_idbrian m. carlson, Mar 12, 2018
  19. 33/36 sha1_file: convert read_sha1_file to struct object_idbrian m. carlson, Mar 12, 2018
  20. 36/36 convert: convert to struct object_idbrian m. carlson, Mar 12, 2018
  21. 29/36 tree-walk: convert get_tree_entry_follow_symlinks internals to object_idbrian m. carlson, Mar 12, 2018
  22. 32/36 sha1_file: convert read_object_with_reference to object_idbrian m. carlson, Mar 12, 2018
  23. 35/36 sha1_file: introduce a constant for max header lengthbrian m. carlson, Mar 12, 2018
  24. 24/36 packfile: convert unpack_entry to struct object_idbrian m. carlson, Mar 12, 2018
  25. 31/36 tree-walk: convert tree entry functions to object_idbrian m. carlson, Mar 12, 2018
  26. 19/36 sha1_file: convert check_sha1_signature to struct object_idbrian m. carlson, Mar 12, 2018
  27. 21/36 builtin/mktree: convert to struct object_idbrian m. carlson, Mar 12, 2018
  28. 14/36 builtin/mktag: convert to struct object_idbrian m. carlson, Mar 12, 2018
  29. 18/36 sha1_file: convert read_loose_object to use struct object_idbrian m. carlson, Mar 12, 2018
  30. 12/36 send-pack: convert remaining functions to struct object_idbrian m. carlson, Mar 12, 2018
  31. 15/36 archive: convert write_archive_entry_fn_t to object_idbrian m. carlson, Mar 12, 2018
  32. 17/36 builtin/index-pack: convert struct ref_delta_entry to object_idbrian m. carlson, Mar 12, 2018
  33. 09/36 wt-status: convert struct wt_status_state to object_idbrian m. carlson, Mar 12, 2018
  34. 11/36 http-walker: convert struct object_request to use struct object_idbrian m. carlson, Mar 12, 2018
  35. 05/36 resolve-undo: convert struct resolve_undo_info to object_idbrian m. carlson, Mar 12, 2018
  36. 10/36 Convert find_unique_abbrev* to struct object_idbrian m. carlson, Mar 12, 2018
  37. 02/36 builtin/write-tree: convert to struct object_idbrian m. carlson, Mar 12, 2018
  38. Junio C HamanoMar 14, 2018
  39. Junio C HamanoMar 14, 2018
  40. brian m. carlsonMar 15, 2018
  41. Junio C HamanoMar 14, 2018
  42. brian m. carlsonMar 15, 2018

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.