@matheusbsbs / matheus-bagliano / commits / 885a86abe2
Fork 0

Shrink "struct object" a bit

This shrinks "struct object" by a small amount, by getting rid of the "struct type *" pointer and replacing it with a 3-bit bitfield instead. In addition, we merge the bitfields and the "flags" field, which incidentally should also remove a useless 4-byte padding from the object when in 64-bit mode. Now, our "struct object" is still too damn large, but it's now less obviously bloated, and of the remaining fields, only the "util" (which is not used by most things) is clearly something that should be eventually discarded. This shrinks the "git-rev-list --all" memory use by about 2.5% on the kernel archive (and, perhaps more importantly, on the larger mozilla archive). That may not sound like much, but I suspect it's more on a 64-bit platform. There are other remaining inefficiencies (the parent lists, for example, probably have horrible malloc overhead), but this was pretty obvious. Most of the patch is just changing the comparison of the "type" pointer from one of the constant string pointers to the appropriate new TYPE_xxx small integer constant. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Jun 14, 2006 at 16:45 UTC 885a86abe2e9f7b96a4e2012183c6751635840aa
21 files changed +113 -96
blob.c
+5 -5
@@ -10,14 +10,14 @@ struct blob *lookup_blob(const unsigned char *sha1)
10 if (!obj) {
11 struct blob *ret = xcalloc(1, sizeof(struct blob));
12 created_object(sha1, &ret->object);
13 - ret->object.type = blob_type;
13 + ret->object.type = TYPE_BLOB;
14 return ret;
15 }
16 if (!obj->type)
17 - obj->type = blob_type;
18 - if (obj->type != blob_type) {
19 - error("Object %s is a %s, not a blob",
20 - sha1_to_hex(sha1), obj->type);
17 + obj->type = TYPE_BLOB;
18 + if (obj->type != TYPE_BLOB) {
19 + error("Object %s is a %s, not a blob",
20 + sha1_to_hex(sha1), typename(obj->type));
21 return NULL;
22 }
23 return (struct blob *) obj;
builtin-diff.c
+3 -3
@@ -303,9 +303,9 @@ int cmd_diff(int argc, const char **argv, char **envp)
303 obj = deref_tag(obj, NULL, 0);
304 if (!obj)
305 die("invalid object '%s' given.", name);
306 - if (!strcmp(obj->type, commit_type))
306 + if (obj->type == TYPE_COMMIT)
307 obj = &((struct commit *)obj)->tree->object;
308 - if (!strcmp(obj->type, tree_type)) {
308 + if (obj->type == TYPE_TREE) {
309 if (ARRAY_SIZE(ent) <= ents)
310 die("more than %d trees given: '%s'",
311 (int) ARRAY_SIZE(ent), name);
@@ -315,7 +315,7 @@ int cmd_diff(int argc, const char **argv, char **envp)
315 ents++;
316 continue;
317 }
318 - if (!strcmp(obj->type, blob_type)) {
318 + if (obj->type == TYPE_BLOB) {
319 if (2 <= blobs)
320 die("more than two blobs given: '%s'", name);
321 memcpy(blob[blobs].sha1, obj->sha1, 20);
builtin-grep.c
+3 -4
@@ -630,10 +630,9 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
630 static int grep_object(struct grep_opt *opt, const char **paths,
631 struct object *obj, const char *name)
632 {
633 - if (!strcmp(obj->type, blob_type))
633 + if (obj->type == TYPE_BLOB)
634 return grep_sha1(opt, obj->sha1, name);
635 - if (!strcmp(obj->type, commit_type) ||
636 - !strcmp(obj->type, tree_type)) {
635 + if (obj->type == TYPE_COMMIT || obj->type == TYPE_TREE) {
636 struct tree_desc tree;
637 void *data;
638 int hit;
@@ -646,7 +645,7 @@ static int grep_object(struct grep_opt *opt, const char **paths,
645 free(data);
646 return hit;
647 }
649 - die("unable to grep from object of type %s", obj->type);
648 + die("unable to grep from object of type %s", typename(obj->type));
649 }
650
651 static const char builtin_grep_usage[] =
builtin-rev-list.c
+3 -3
@@ -158,16 +158,16 @@ static void show_commit_list(struct rev_info *revs)
158 const char *name = pending->name;
159 if (obj->flags & (UNINTERESTING | SEEN))
160 continue;
161 - if (obj->type == tag_type) {
161 + if (obj->type == TYPE_TAG) {
162 obj->flags |= SEEN;
163 p = add_object(obj, p, NULL, name);
164 continue;
165 }
166 - if (obj->type == tree_type) {
166 + if (obj->type == TYPE_TREE) {
167 p = process_tree((struct tree *)obj, p, NULL, name);
168 continue;
169 }
170 - if (obj->type == blob_type) {
170 + if (obj->type == TYPE_BLOB) {
171 p = process_blob((struct blob *)obj, p, NULL, name);
172 continue;
173 }
builtin-show-branch.c
+1 -1
@@ -15,7 +15,7 @@ static const char **default_arg = NULL;
15 #define UNINTERESTING 01
16
17 #define REV_SHIFT 2
18 -#define MAX_REVS 29 /* should not exceed bits_per_int - REV_SHIFT */
18 +#define MAX_REVS (FLAG_BITS - REV_SHIFT) /* should not exceed bits_per_int - REV_SHIFT */
19
20 static struct commit *interesting(struct commit_list *list)
21 {
commit.c
+4 -4
@@ -56,10 +56,10 @@ static struct commit *check_commit(struct object *obj,
56 const unsigned char *sha1,
57 int quiet)
58 {
59 - if (obj->type != commit_type) {
59 + if (obj->type != TYPE_COMMIT) {
60 if (!quiet)
61 error("Object %s is a %s, not a commit",
62 - sha1_to_hex(sha1), obj->type);
62 + sha1_to_hex(sha1), typename(obj->type));
63 return NULL;
64 }
65 return (struct commit *) obj;
@@ -86,11 +86,11 @@ struct commit *lookup_commit(const unsigned char *sha1)
86 if (!obj) {
87 struct commit *ret = xcalloc(1, sizeof(struct commit));
88 created_object(sha1, &ret->object);
89 - ret->object.type = commit_type;
89 + ret->object.type = TYPE_COMMIT;
90 return ret;
91 }
92 if (!obj->type)
93 - obj->type = commit_type;
93 + obj->type = TYPE_COMMIT;
94 return check_commit(obj, sha1, 0);
95 }
96
describe.c
+1 -1
@@ -67,7 +67,7 @@ static int get_name(const char *path, const unsigned char *sha1)
67 * Otherwise only annotated tags are used.
68 */
69 if (!strncmp(path, "refs/tags/", 10)) {
70 - if (object->type == tag_type)
70 + if (object->type == TYPE_TAG)
71 prio = 2;
72 else
73 prio = 1;
fetch-pack.c
+5 -5
@@ -46,7 +46,7 @@ static int rev_list_insert_ref(const char *path, const unsigned char *sha1)
46 {
47 struct object *o = deref_tag(parse_object(sha1), path, 0);
48
49 - if (o && o->type == commit_type)
49 + if (o && o->type == TYPE_COMMIT)
50 rev_list_push((struct commit *)o, SEEN);
51
52 return 0;
@@ -251,14 +251,14 @@ static int mark_complete(const char *path, const unsigned char *sha1)
251 {
252 struct object *o = parse_object(sha1);
253
254 - while (o && o->type == tag_type) {
254 + while (o && o->type == TYPE_TAG) {
255 struct tag *t = (struct tag *) o;
256 if (!t->tagged)
257 break; /* broken repository */
258 o->flags |= COMPLETE;
259 o = parse_object(t->tagged->sha1);
260 }
261 - if (o && o->type == commit_type) {
261 + if (o && o->type == TYPE_COMMIT) {
262 struct commit *commit = (struct commit *)o;
263 commit->object.flags |= COMPLETE;
264 insert_by_date(commit, &complete);
@@ -352,7 +352,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
352 * in sync with the other side at some time after
353 * that (it is OK if we guess wrong here).
354 */
355 - if (o->type == commit_type) {
355 + if (o->type == TYPE_COMMIT) {
356 struct commit *commit = (struct commit *)o;
357 if (!cutoff || cutoff < commit->date)
358 cutoff = commit->date;
@@ -371,7 +371,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
371 struct object *o = deref_tag(lookup_object(ref->old_sha1),
372 NULL, 0);
373
374 - if (!o || o->type != commit_type || !(o->flags & COMPLETE))
374 + if (!o || o->type != TYPE_COMMIT || !(o->flags & COMPLETE))
375 continue;
376
377 if (!(o->flags & SEEN)) {
fetch.c
+6 -8
@@ -118,27 +118,27 @@ static struct object_list **process_queue_end = &process_queue;
118
119 static int process_object(struct object *obj)
120 {
121 - if (obj->type == commit_type) {
121 + if (obj->type == TYPE_COMMIT) {
122 if (process_commit((struct commit *)obj))
123 return -1;
124 return 0;
125 }
126 - if (obj->type == tree_type) {
126 + if (obj->type == TYPE_TREE) {
127 if (process_tree((struct tree *)obj))
128 return -1;
129 return 0;
130 }
131 - if (obj->type == blob_type) {
131 + if (obj->type == TYPE_BLOB) {
132 return 0;
133 }
134 - if (obj->type == tag_type) {
134 + if (obj->type == TYPE_TAG) {
135 if (process_tag((struct tag *)obj))
136 return -1;
137 return 0;
138 }
139 return error("Unable to determine requirements "
140 "of type %s for %s",
141 - obj->type, sha1_to_hex(obj->sha1));
141 + typename(obj->type), sha1_to_hex(obj->sha1));
142 }
143
144 static int process(struct object *obj)
@@ -179,9 +179,7 @@ static int loop(void)
179 */
180 if (! (obj->flags & TO_SCAN)) {
181 if (fetch(obj->sha1)) {
182 - report_missing(obj->type
183 - ? obj->type
184 - : "object", obj->sha1);
182 + report_missing(typename(obj->type), obj->sha1);
183 return -1;
184 }
185 }
fsck-objects.c
+13 -13
@@ -34,7 +34,7 @@ static void objreport(struct object *obj, const char *severity,
34 const char *err, va_list params)
35 {
36 fprintf(stderr, "%s in %s %s: ",
37 - severity, obj->type, sha1_to_hex(obj->sha1));
37 + severity, typename(obj->type), sha1_to_hex(obj->sha1));
38 vfprintf(stderr, err, params);
39 fputs("\n", stderr);
40 }
@@ -74,7 +74,7 @@ static void check_connectivity(void)
74 ; /* it is in pack */
75 else
76 printf("missing %s %s\n",
77 - obj->type, sha1_to_hex(obj->sha1));
77 + typename(obj->type), sha1_to_hex(obj->sha1));
78 continue;
79 }
80
@@ -87,20 +87,20 @@ static void check_connectivity(void)
87 (has_sha1_file(ref->sha1)))
88 continue;
89 printf("broken link from %7s %s\n",
90 - obj->type, sha1_to_hex(obj->sha1));
90 + typename(obj->type), sha1_to_hex(obj->sha1));
91 printf(" to %7s %s\n",
92 - ref->type, sha1_to_hex(ref->sha1));
92 + typename(ref->type), sha1_to_hex(ref->sha1));
93 }
94 }
95
96 if (show_unreachable && !(obj->flags & REACHABLE)) {
97 printf("unreachable %s %s\n",
98 - obj->type, sha1_to_hex(obj->sha1));
98 + typename(obj->type), sha1_to_hex(obj->sha1));
99 continue;
100 }
101
102 if (!obj->used) {
103 - printf("dangling %s %s\n", obj->type,
103 + printf("dangling %s %s\n", typename(obj->type),
104 sha1_to_hex(obj->sha1));
105 }
106 }
@@ -282,7 +282,7 @@ static int fsck_tag(struct tag *tag)
282 if (!show_tags)
283 return 0;
284
285 - printf("tagged %s %s", tagged->type, sha1_to_hex(tagged->sha1));
285 + printf("tagged %s %s", typename(tagged->type), sha1_to_hex(tagged->sha1));
286 printf(" (%s) in %s\n", tag->tag, sha1_to_hex(tag->object.sha1));
287 return 0;
288 }
@@ -295,16 +295,16 @@ static int fsck_sha1(unsigned char *sha1)
295 if (obj->flags & SEEN)
296 return 0;
297 obj->flags |= SEEN;
298 - if (obj->type == blob_type)
298 + if (obj->type == TYPE_BLOB)
299 return 0;
300 - if (obj->type == tree_type)
300 + if (obj->type == TYPE_TREE)
301 return fsck_tree((struct tree *) obj);
302 - if (obj->type == commit_type)
302 + if (obj->type == TYPE_COMMIT)
303 return fsck_commit((struct commit *) obj);
304 - if (obj->type == tag_type)
304 + if (obj->type == TYPE_TAG)
305 return fsck_tag((struct tag *) obj);
306 /* By now, parse_object() would've returned NULL instead. */
307 - return objerror(obj, "unknown type '%s' (internal fsck error)", obj->type);
307 + return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type);
308 }
309
310 /*
@@ -470,7 +470,7 @@ static int fsck_cache_tree(struct cache_tree *it)
470 }
471 mark_reachable(obj, REACHABLE);
472 obj->used = 1;
473 - if (obj->type != tree_type)
473 + if (obj->type != TYPE_TREE)
474 err |= objerror(obj, "non-tree in cache-tree");
475 }
476 for (i = 0; i < it->subtree_nr; i++)
http-push.c
+6 -6
@@ -1773,16 +1773,16 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
1773
1774 if (obj->flags & (UNINTERESTING | SEEN))
1775 continue;
1776 - if (obj->type == tag_type) {
1776 + if (obj->type == TYPE_TAG) {
1777 obj->flags |= SEEN;
1778 p = add_object(obj, p, NULL, name);
1779 continue;
1780 }
1781 - if (obj->type == tree_type) {
1781 + if (obj->type == TYPE_TREE) {
1782 p = process_tree((struct tree *)obj, p, NULL, name);
1783 continue;
1784 }
1785 - if (obj->type == blob_type) {
1785 + if (obj->type == TYPE_BLOB) {
1786 p = process_blob((struct blob *)obj, p, NULL, name);
1787 continue;
1788 }
@@ -1949,12 +1949,12 @@ static int ref_newer(const unsigned char *new_sha1,
1949 * old. Otherwise we require --force.
1950 */
1951 o = deref_tag(parse_object(old_sha1), NULL, 0);
1952 - if (!o || o->type != commit_type)
1952 + if (!o || o->type != TYPE_COMMIT)
1953 return 0;
1954 old = (struct commit *) o;
1955
1956 o = deref_tag(parse_object(new_sha1), NULL, 0);
1957 - if (!o || o->type != commit_type)
1957 + if (!o || o->type != TYPE_COMMIT)
1958 return 0;
1959 new = (struct commit *) o;
1960
@@ -2033,7 +2033,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
2033 fwrite_buffer(ref_info, 1, len, buf);
2034 free(ref_info);
2035
2036 - if (o->type == tag_type) {
2036 + if (o->type == TYPE_TAG) {
2037 o = deref_tag(o, ls->dentry_name, 0);
2038 if (o) {
2039 len = strlen(ls->dentry_name) + 45;
name-rev.c
+3 -3
@@ -84,14 +84,14 @@ static int name_ref(const char *path, const unsigned char *sha1)
84 if (tags_only && strncmp(path, "refs/tags/", 10))
85 return 0;
86
87 - while (o && o->type == tag_type) {
87 + while (o && o->type == TYPE_TAG) {
88 struct tag *t = (struct tag *) o;
89 if (!t->tagged)
90 break; /* broken repository */
91 o = parse_object(t->tagged->sha1);
92 deref = 1;
93 }
94 - if (o && o->type == commit_type) {
94 + if (o && o->type == TYPE_COMMIT) {
95 struct commit *commit = (struct commit *)o;
96
97 if (!strncmp(path, "refs/heads/", 11))
@@ -167,7 +167,7 @@ int main(int argc, char **argv)
167 }
168
169 o = deref_tag(parse_object(sha1), *argv, 0);
170 - if (!o || o->type != commit_type) {
170 + if (!o || o->type != TYPE_COMMIT) {
171 fprintf(stderr, "Could not get commit for %s. Skipping.\n",
172 *argv);
173 continue;
object.c
+6 -2
@@ -9,6 +9,10 @@ struct object **objs;
9 static int nr_objs;
10 int obj_allocs;
11
12 +const char *type_names[] = {
13 + "none", "blob", "tree", "commit", "bad"
14 +};
15 +
16 int track_object_refs = 0;
17
18 static int hashtable_index(const unsigned char *sha1)
@@ -50,7 +54,7 @@ void created_object(const unsigned char *sha1, struct object *obj)
54
55 obj->parsed = 0;
56 memcpy(obj->sha1, sha1, 20);
53 - obj->type = NULL;
57 + obj->type = TYPE_NONE;
58 obj->refs = NULL;
59 obj->used = 0;
60
@@ -179,7 +183,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
183 if (!obj) {
184 union any_object *ret = xcalloc(1, sizeof(*ret));
185 created_object(sha1, &ret->object);
182 - ret->object.type = NULL;
186 + ret->object.type = TYPE_NONE;
187 return &ret->object;
188 }
189 return obj;
object.h
+18 -2
@@ -12,12 +12,22 @@ struct object_refs {
12 struct object *ref[FLEX_ARRAY]; /* more */
13 };
14
15 +#define TYPE_BITS 3
16 +#define FLAG_BITS 27
17 +
18 +#define TYPE_NONE 0
19 +#define TYPE_BLOB 1
20 +#define TYPE_TREE 2
21 +#define TYPE_COMMIT 3
22 +#define TYPE_TAG 4
23 +#define TYPE_BAD 5
24 +
25 struct object {
26 unsigned parsed : 1;
27 unsigned used : 1;
18 - unsigned int flags;
28 + unsigned type : TYPE_BITS;
29 + unsigned flags : FLAG_BITS;
30 unsigned char sha1[20];
20 - const char *type;
31 struct object_refs *refs;
32 void *util;
33 };
@@ -25,6 +35,12 @@ struct object {
35 extern int track_object_refs;
36 extern int obj_allocs;
37 extern struct object **objs;
38 +extern const char *type_names[];
39 +
40 +static inline const char *typename(unsigned int type)
41 +{
42 + return type_names[type > TYPE_TAG ? TYPE_BAD : type];
43 +}
44
45 /** Internal only **/
46 struct object *lookup_object(const unsigned char *sha1);
revision.c
+6 -6
@@ -140,7 +140,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
140 /*
141 * Tag object? Look what it points to..
142 */
143 - while (object->type == tag_type) {
143 + while (object->type == TYPE_TAG) {
144 struct tag *tag = (struct tag *) object;
145 if (revs->tag_objects && !(flags & UNINTERESTING))
146 add_pending_object(revs, object, tag->tag);
@@ -153,7 +153,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
153 * Commit object? Just return it, we'll do all the complex
154 * reachability crud.
155 */
156 - if (object->type == commit_type) {
156 + if (object->type == TYPE_COMMIT) {
157 struct commit *commit = (struct commit *)object;
158 if (parse_commit(commit) < 0)
159 die("unable to parse commit %s", name);
@@ -169,7 +169,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
169 * Tree object? Either mark it uniniteresting, or add it
170 * to the list of objects to look at later..
171 */
172 - if (object->type == tree_type) {
172 + if (object->type == TYPE_TREE) {
173 struct tree *tree = (struct tree *)object;
174 if (!revs->tree_objects)
175 return NULL;
@@ -184,7 +184,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
184 /*
185 * Blob object? You know the drill by now..
186 */
187 - if (object->type == blob_type) {
187 + if (object->type == TYPE_BLOB) {
188 struct blob *blob = (struct blob *)object;
189 if (!revs->blob_objects)
190 return NULL;
@@ -498,11 +498,11 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
498 return 0;
499 while (1) {
500 it = get_reference(revs, arg, sha1, 0);
501 - if (strcmp(it->type, tag_type))
501 + if (it->type != TYPE_TAG)
502 break;
503 memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20);
504 }
505 - if (strcmp(it->type, commit_type))
505 + if (it->type != TYPE_COMMIT)
506 return 0;
507 commit = (struct commit *)it;
508 for (parents = commit->parents; parents; parents = parents->next) {
send-pack.c
+2 -2
@@ -151,12 +151,12 @@ static int ref_newer(const unsigned char *new_sha1,
151 * old. Otherwise we require --force.
152 */
153 o = deref_tag(parse_object(old_sha1), NULL, 0);
154 - if (!o || o->type != commit_type)
154 + if (!o || o->type != TYPE_COMMIT)
155 return 0;
156 old = (struct commit *) o;
157
158 o = deref_tag(parse_object(new_sha1), NULL, 0);
159 - if (!o || o->type != commit_type)
159 + if (!o || o->type != TYPE_COMMIT)
160 return 0;
161 new = (struct commit *) o;
162
server-info.c
+1 -1
@@ -12,7 +12,7 @@ static int add_info_ref(const char *path, const unsigned char *sha1)
12 struct object *o = parse_object(sha1);
13
14 fprintf(info_ref_fp, "%s %s\n", sha1_to_hex(sha1), path);
15 - if (o->type == tag_type) {
15 + if (o->type == TYPE_TAG) {
16 o = deref_tag(o, path, 0);
17 if (o)
18 fprintf(info_ref_fp, "%s %s^{}\n",
sha1_name.c
+11 -11
@@ -357,7 +357,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
357 {
358 unsigned char outer[20];
359 const char *sp;
360 - const char *type_string = NULL;
360 + unsigned int expected_type = 0;
361 struct object *o;
362
363 /*
@@ -381,13 +381,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
381
382 sp++; /* beginning of type name, or closing brace for empty */
383 if (!strncmp(commit_type, sp, 6) && sp[6] == '}')
384 - type_string = commit_type;
384 + expected_type = TYPE_COMMIT;
385 else if (!strncmp(tree_type, sp, 4) && sp[4] == '}')
386 - type_string = tree_type;
386 + expected_type = TYPE_TREE;
387 else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
388 - type_string = blob_type;
388 + expected_type = TYPE_BLOB;
389 else if (sp[0] == '}')
390 - type_string = NULL;
390 + expected_type = TYPE_NONE;
391 else
392 return -1;
393
@@ -397,7 +397,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
397 o = parse_object(outer);
398 if (!o)
399 return -1;
400 - if (!type_string) {
400 + if (!expected_type) {
401 o = deref_tag(o, name, sp - name - 2);
402 if (!o || (!o->parsed && !parse_object(o->sha1)))
403 return -1;
@@ -412,18 +412,18 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
412 while (1) {
413 if (!o || (!o->parsed && !parse_object(o->sha1)))
414 return -1;
415 - if (o->type == type_string) {
415 + if (o->type == expected_type) {
416 memcpy(sha1, o->sha1, 20);
417 return 0;
418 }
419 - if (o->type == tag_type)
419 + if (o->type == TYPE_TAG)
420 o = ((struct tag*) o)->tagged;
421 - else if (o->type == commit_type)
421 + else if (o->type == TYPE_COMMIT)
422 o = &(((struct commit *) o)->tree->object);
423 else
424 return error("%.*s: expected %s type, but the object dereferences to %s type",
425 - len, name, type_string,
426 - o->type);
425 + len, name, typename(expected_type),
426 + typename(o->type));
427 if (!o->parsed)
428 parse_object(o->sha1);
429 }
tag.c
+6 -6
@@ -5,7 +5,7 @@ const char *tag_type = "tag";
5
6 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
7 {
8 - while (o && o->type == tag_type)
8 + while (o && o->type == TYPE_TAG)
9 o = parse_object(((struct tag *)o)->tagged->sha1);
10 if (!o && warn) {
11 if (!warnlen)
@@ -21,14 +21,14 @@ struct tag *lookup_tag(const unsigned char *sha1)
21 if (!obj) {
22 struct tag *ret = xcalloc(1, sizeof(struct tag));
23 created_object(sha1, &ret->object);
24 - ret->object.type = tag_type;
24 + ret->object.type = TYPE_TAG;
25 return ret;
26 }
27 if (!obj->type)
28 - obj->type = tag_type;
29 - if (obj->type != tag_type) {
30 - error("Object %s is a %s, not a tree",
31 - sha1_to_hex(sha1), obj->type);
28 + obj->type = TYPE_TAG;
29 + if (obj->type != TYPE_TAG) {
30 + error("Object %s is a %s, not a tree",
31 + sha1_to_hex(sha1), typename(obj->type));
32 return NULL;
33 }
34 return (struct tag *) obj;
tree.c
+8 -8
@@ -131,14 +131,14 @@ struct tree *lookup_tree(const unsigned char *sha1)
131 if (!obj) {
132 struct tree *ret = xcalloc(1, sizeof(struct tree));
133 created_object(sha1, &ret->object);
134 - ret->object.type = tree_type;
134 + ret->object.type = TYPE_TREE;
135 return ret;
136 }
137 if (!obj->type)
138 - obj->type = tree_type;
139 - if (obj->type != tree_type) {
140 - error("Object %s is a %s, not a tree",
141 - sha1_to_hex(sha1), obj->type);
138 + obj->type = TYPE_TREE;
139 + if (obj->type != TYPE_TREE) {
140 + error("Object %s is a %s, not a tree",
141 + sha1_to_hex(sha1), typename(obj->type));
142 return NULL;
143 }
144 return (struct tree *) obj;
@@ -216,11 +216,11 @@ struct tree *parse_tree_indirect(const unsigned char *sha1)
216 do {
217 if (!obj)
218 return NULL;
219 - if (obj->type == tree_type)
219 + if (obj->type == TYPE_TREE)
220 return (struct tree *) obj;
221 - else if (obj->type == commit_type)
221 + else if (obj->type == TYPE_COMMIT)
222 obj = &(((struct commit *) obj)->tree->object);
223 - else if (obj->type == tag_type)
223 + else if (obj->type == TYPE_TAG)
224 obj = ((struct tag *) obj)->tagged;
225 else
226 return NULL;
upload-pack.c
+2 -2
@@ -105,7 +105,7 @@ static int got_sha1(char *hex, unsigned char *sha1)
105 o = parse_object(sha1);
106 if (!o)
107 die("oops (%s)", sha1_to_hex(sha1));
108 - if (o->type == commit_type) {
108 + if (o->type == TYPE_COMMIT) {
109 struct commit_list *parents;
110 if (o->flags & THEY_HAVE)
111 return 0;
@@ -234,7 +234,7 @@ static int send_ref(const char *refname, const unsigned char *sha1)
234 o->flags |= OUR_REF;
235 nr_our_refs++;
236 }
237 - if (o->type == tag_type) {
237 + if (o->type == TYPE_TAG) {
238 o = deref_tag(o, refname, 0);
239 packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
240 }