@matheusbsbs / matheus-bagliano / commits / 66035a6b3d
Fork 0

Cleanup check_valid in commit-tree.

This routine should be using the object_type enum rather than a string comparsion, as the expected type is always supplied and is known at compile time. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Feb 27, 2007 at 10:00 UTC 66035a6b3d629b546daef3784f5351d58f4f17b1
1 file changed +5 -5
builtin-commit-tree.c
+5 -5
@@ -45,14 +45,14 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
45 memcpy(buf + size, one_line, len);
46 }
47
48 -static void check_valid(unsigned char *sha1, const char *expect)
48 +static void check_valid(unsigned char *sha1, enum object_type expect)
49 {
50 enum object_type type = sha1_object_info(sha1, NULL);
51 if (type < 0)
52 die("%s is not a valid object", sha1_to_hex(sha1));
53 - if (expect && type != type_from_string(expect))
53 + if (type != expect)
54 die("%s is not a valid '%s' object", sha1_to_hex(sha1),
55 - expect);
55 + typename(expect));
56 }
57
58 /*
@@ -100,7 +100,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
100 if (get_sha1(argv[1], tree_sha1))
101 die("Not a valid object name %s", argv[1]);
102
103 - check_valid(tree_sha1, tree_type);
103 + check_valid(tree_sha1, OBJ_TREE);
104 for (i = 2; i < argc; i += 2) {
105 const char *a, *b;
106 a = argv[i]; b = argv[i+1];
@@ -111,7 +111,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
111 die("Too many parents (%d max)", MAXPARENT);
112 if (get_sha1(b, parent_sha1[parents]))
113 die("Not a valid object name %s", b);
114 - check_valid(parent_sha1[parents], commit_type);
114 + check_valid(parent_sha1[parents], OBJ_COMMIT);
115 if (new_parent(parents))
116 parents++;
117 }