@matheusbsbs / matheus-bagliano / commits / 0ab179504a
Fork 0

get rid of lookup_object_type()

This function is called only once in the whole source tree. Let's move its code inline instead, which is also in the spirit of removing as much object type char arrays as possible (not that this patch does anything for that but at least it is now a local matter). Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Feb 26, 2007 at 14:56 UTC 0ab179504a17907c395a4009f7c23d2f71bba1d3
3 files changed +18 -24
object.c
-18
@@ -120,24 +120,6 @@ void created_object(const unsigned char *sha1, struct object *obj)
120 nr_objs++;
121 }
122
123 -struct object *lookup_object_type(const unsigned char *sha1, const char *type)
124 -{
125 - if (!type) {
126 - return lookup_unknown_object(sha1);
127 - } else if (!strcmp(type, blob_type)) {
128 - return &lookup_blob(sha1)->object;
129 - } else if (!strcmp(type, tree_type)) {
130 - return &lookup_tree(sha1)->object;
131 - } else if (!strcmp(type, commit_type)) {
132 - return &lookup_commit(sha1)->object;
133 - } else if (!strcmp(type, tag_type)) {
134 - return &lookup_tag(sha1)->object;
135 - } else {
136 - error("Unknown type %s", type);
137 - return NULL;
138 - }
139 -}
140 -
123 union any_object {
124 struct object object;
125 struct commit commit;
object.h
-3
@@ -47,9 +47,6 @@ extern struct object_refs *lookup_object_refs(struct object *);
47 /** Internal only **/
48 struct object *lookup_object(const unsigned char *sha1);
49
50 -/** Returns the object, having looked it up as being the given type. **/
51 -struct object *lookup_object_type(const unsigned char *sha1, const char *type);
52 -
50 void created_object(const unsigned char *sha1, struct object *obj);
51
52 /** Returns the object, having parsed it to find out what it is. **/
tag.c
+18 -3
@@ -1,5 +1,8 @@
1 #include "cache.h"
2 #include "tag.h"
3 +#include "commit.h"
4 +#include "tree.h"
5 +#include "blob.h"
6
7 const char *tag_type = "tag";
8
@@ -37,7 +40,7 @@ struct tag *lookup_tag(const unsigned char *sha1)
40 int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
41 {
42 int typelen, taglen;
40 - unsigned char object[20];
43 + unsigned char sha1[20];
44 const char *type_line, *tag_line, *sig_line;
45 char type[20];
46
@@ -47,7 +50,7 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
50
51 if (size < 64)
52 return -1;
50 - if (memcmp("object ", data, 7) || get_sha1_hex((char *) data + 7, object))
53 + if (memcmp("object ", data, 7) || get_sha1_hex((char *) data + 7, sha1))
54 return -1;
55
56 type_line = (char *) data + 48;
@@ -73,7 +76,19 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
76 memcpy(item->tag, tag_line + 4, taglen);
77 item->tag[taglen] = '\0';
78
76 - item->tagged = lookup_object_type(object, type);
79 + if (!strcmp(type, blob_type)) {
80 + item->tagged = &lookup_blob(sha1)->object;
81 + } else if (!strcmp(type, tree_type)) {
82 + item->tagged = &lookup_tree(sha1)->object;
83 + } else if (!strcmp(type, commit_type)) {
84 + item->tagged = &lookup_commit(sha1)->object;
85 + } else if (!strcmp(type, tag_type)) {
86 + item->tagged = &lookup_tag(sha1)->object;
87 + } else {
88 + error("Unknown type %s", type);
89 + item->tagged = NULL;
90 + }
91 +
92 if (item->tagged && track_object_refs) {
93 struct object_refs *refs = alloc_object_refs(1);
94 refs->ref[0] = item->tagged;