Browse Source

sha1_file: convert assert_sha1_type to object_id

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
brian m. carlson 7 years ago committed by Junio C Hamano
parent
commit
e816caa07b
  1. 2
      builtin/commit-tree.c
  2. 2
      cache.h
  3. 2
      commit.c
  4. 8
      sha1_file.c

2
builtin/commit-tree.c

@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
usage(commit_tree_usage); usage(commit_tree_usage);
if (get_oid_commit(argv[i], &oid)) if (get_oid_commit(argv[i], &oid))
die("Not a valid object name %s", argv[i]); 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); new_parent(lookup_commit(&oid), &parents);
continue; continue;
} }

2
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 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 */ /* Helper to check and "touch" a file */
extern int check_and_freshen_file(const char *fn, int freshen); extern int check_and_freshen_file(const char *fn, int freshen);

2
commit.c

@ -1517,7 +1517,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
int encoding_is_utf8; int encoding_is_utf8;
struct strbuf buffer; struct strbuf buffer;


assert_sha1_type(tree->hash, OBJ_TREE); assert_oid_type(tree, OBJ_TREE);


if (memchr(msg, '\0', msg_len)) if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed."); return error("a NUL byte in commit log message not allowed.");

8
sha1_file.c

@ -1966,13 +1966,13 @@ int read_pack_header(int fd, struct pack_header *header)
return 0; 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) 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) 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)); type_name(expect));
} }



Loading…
Cancel
Save