Skip to content

Commit 5cd060b

Browse files
author
Junio C Hamano
committed
Merge branch 'lt/unitype'
* lt/unitype: builtin-prune.c: forgot TYPE => OBJ changes. Remove TYPE_* constant macros and use object_type enums consistently.
2 parents 1733832 + e5a78b1 commit 5cd060b

23 files changed

+90
-95
lines changed

blob.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ struct blob *lookup_blob(const unsigned char *sha1)
1010
if (!obj) {
1111
struct blob *ret = alloc_blob_node();
1212
created_object(sha1, &ret->object);
13-
ret->object.type = TYPE_BLOB;
13+
ret->object.type = OBJ_BLOB;
1414
return ret;
1515
}
1616
if (!obj->type)
17-
obj->type = TYPE_BLOB;
18-
if (obj->type != TYPE_BLOB) {
17+
obj->type = OBJ_BLOB;
18+
if (obj->type != OBJ_BLOB) {
1919
error("Object %s is a %s, not a blob",
2020
sha1_to_hex(sha1), typename(obj->type));
2121
return NULL;

builtin-diff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ int cmd_diff(int argc, const char **argv, char **envp)
285285
obj = deref_tag(obj, NULL, 0);
286286
if (!obj)
287287
die("invalid object '%s' given.", name);
288-
if (obj->type == TYPE_COMMIT)
288+
if (obj->type == OBJ_COMMIT)
289289
obj = &((struct commit *)obj)->tree->object;
290-
if (obj->type == TYPE_TREE) {
290+
if (obj->type == OBJ_TREE) {
291291
if (ARRAY_SIZE(ent) <= ents)
292292
die("more than %d trees given: '%s'",
293293
(int) ARRAY_SIZE(ent), name);
@@ -297,7 +297,7 @@ int cmd_diff(int argc, const char **argv, char **envp)
297297
ents++;
298298
continue;
299299
}
300-
if (obj->type == TYPE_BLOB) {
300+
if (obj->type == OBJ_BLOB) {
301301
if (2 <= blobs)
302302
die("more than two blobs given: '%s'", name);
303303
memcpy(blob[blobs].sha1, obj->sha1, 20);

builtin-fmt-merge-msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void shortlog(const char *name, unsigned char *sha1,
181181
int flags = UNINTERESTING | TREECHANGE | SEEN | SHOWN | ADDED;
182182

183183
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
184-
if (!branch || branch->type != TYPE_COMMIT)
184+
if (!branch || branch->type != OBJ_COMMIT)
185185
return;
186186

187187
setup_revisions(0, NULL, rev, NULL);

builtin-grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
891891
static int grep_object(struct grep_opt *opt, const char **paths,
892892
struct object *obj, const char *name)
893893
{
894-
if (obj->type == TYPE_BLOB)
894+
if (obj->type == OBJ_BLOB)
895895
return grep_sha1(opt, obj->sha1, name);
896-
if (obj->type == TYPE_COMMIT || obj->type == TYPE_TREE) {
896+
if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
897897
struct tree_desc tree;
898898
void *data;
899899
int hit;

builtin-prune.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ static void walk_commit_list(struct rev_info *revs)
158158
struct object_array_entry *pending = revs->pending.objects + i;
159159
struct object *obj = pending->item;
160160
const char *name = pending->name;
161-
if (obj->type == TYPE_TAG) {
161+
if (obj->type == OBJ_TAG) {
162162
process_tag((struct tag *) obj, &objects, name);
163163
continue;
164164
}
165-
if (obj->type == TYPE_TREE) {
165+
if (obj->type == OBJ_TREE) {
166166
process_tree((struct tree *)obj, &objects, NULL, name);
167167
continue;
168168
}
169-
if (obj->type == TYPE_BLOB) {
169+
if (obj->type == OBJ_BLOB) {
170170
process_blob((struct blob *)obj, &objects, NULL, name);
171171
continue;
172172
}

builtin-rev-list.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ static void show_commit_list(struct rev_info *revs)
167167
const char *name = pending->name;
168168
if (obj->flags & (UNINTERESTING | SEEN))
169169
continue;
170-
if (obj->type == TYPE_TAG) {
170+
if (obj->type == OBJ_TAG) {
171171
obj->flags |= SEEN;
172172
add_object_array(obj, name, &objects);
173173
continue;
174174
}
175-
if (obj->type == TYPE_TREE) {
175+
if (obj->type == OBJ_TREE) {
176176
process_tree((struct tree *)obj, &objects, NULL, name);
177177
continue;
178178
}
179-
if (obj->type == TYPE_BLOB) {
179+
if (obj->type == OBJ_BLOB) {
180180
process_blob((struct blob *)obj, &objects, NULL, name);
181181
continue;
182182
}

commit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static struct commit *check_commit(struct object *obj,
5656
const unsigned char *sha1,
5757
int quiet)
5858
{
59-
if (obj->type != TYPE_COMMIT) {
59+
if (obj->type != OBJ_COMMIT) {
6060
if (!quiet)
6161
error("Object %s is a %s, not a commit",
6262
sha1_to_hex(sha1), typename(obj->type));
@@ -86,11 +86,11 @@ struct commit *lookup_commit(const unsigned char *sha1)
8686
if (!obj) {
8787
struct commit *ret = alloc_commit_node();
8888
created_object(sha1, &ret->object);
89-
ret->object.type = TYPE_COMMIT;
89+
ret->object.type = OBJ_COMMIT;
9090
return ret;
9191
}
9292
if (!obj->type)
93-
obj->type = TYPE_COMMIT;
93+
obj->type = OBJ_COMMIT;
9494
return check_commit(obj, sha1, 0);
9595
}
9696

describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int get_name(const char *path, const unsigned char *sha1)
6767
* Otherwise only annotated tags are used.
6868
*/
6969
if (!strncmp(path, "refs/tags/", 10)) {
70-
if (object->type == TYPE_TAG)
70+
if (object->type == OBJ_TAG)
7171
prio = 2;
7272
else
7373
prio = 1;

fetch-pack.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static int rev_list_insert_ref(const char *path, const unsigned char *sha1)
4646
{
4747
struct object *o = deref_tag(parse_object(sha1), path, 0);
4848

49-
if (o && o->type == TYPE_COMMIT)
49+
if (o && o->type == OBJ_COMMIT)
5050
rev_list_push((struct commit *)o, SEEN);
5151

5252
return 0;
@@ -256,14 +256,14 @@ static int mark_complete(const char *path, const unsigned char *sha1)
256256
{
257257
struct object *o = parse_object(sha1);
258258

259-
while (o && o->type == TYPE_TAG) {
259+
while (o && o->type == OBJ_TAG) {
260260
struct tag *t = (struct tag *) o;
261261
if (!t->tagged)
262262
break; /* broken repository */
263263
o->flags |= COMPLETE;
264264
o = parse_object(t->tagged->sha1);
265265
}
266-
if (o && o->type == TYPE_COMMIT) {
266+
if (o && o->type == OBJ_COMMIT) {
267267
struct commit *commit = (struct commit *)o;
268268
commit->object.flags |= COMPLETE;
269269
insert_by_date(commit, &complete);
@@ -357,7 +357,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
357357
* in sync with the other side at some time after
358358
* that (it is OK if we guess wrong here).
359359
*/
360-
if (o->type == TYPE_COMMIT) {
360+
if (o->type == OBJ_COMMIT) {
361361
struct commit *commit = (struct commit *)o;
362362
if (!cutoff || cutoff < commit->date)
363363
cutoff = commit->date;
@@ -376,7 +376,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
376376
struct object *o = deref_tag(lookup_object(ref->old_sha1),
377377
NULL, 0);
378378

379-
if (!o || o->type != TYPE_COMMIT || !(o->flags & COMPLETE))
379+
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
380380
continue;
381381

382382
if (!(o->flags & SEEN)) {

fetch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,20 @@ static struct object_list **process_queue_end = &process_queue;
118118

119119
static int process_object(struct object *obj)
120120
{
121-
if (obj->type == TYPE_COMMIT) {
121+
if (obj->type == OBJ_COMMIT) {
122122
if (process_commit((struct commit *)obj))
123123
return -1;
124124
return 0;
125125
}
126-
if (obj->type == TYPE_TREE) {
126+
if (obj->type == OBJ_TREE) {
127127
if (process_tree((struct tree *)obj))
128128
return -1;
129129
return 0;
130130
}
131-
if (obj->type == TYPE_BLOB) {
131+
if (obj->type == OBJ_BLOB) {
132132
return 0;
133133
}
134-
if (obj->type == TYPE_TAG) {
134+
if (obj->type == OBJ_TAG) {
135135
if (process_tag((struct tag *)obj))
136136
return -1;
137137
return 0;

fsck-objects.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@ static int fsck_sha1(unsigned char *sha1)
297297
if (obj->flags & SEEN)
298298
return 0;
299299
obj->flags |= SEEN;
300-
if (obj->type == TYPE_BLOB)
300+
if (obj->type == OBJ_BLOB)
301301
return 0;
302-
if (obj->type == TYPE_TREE)
302+
if (obj->type == OBJ_TREE)
303303
return fsck_tree((struct tree *) obj);
304-
if (obj->type == TYPE_COMMIT)
304+
if (obj->type == OBJ_COMMIT)
305305
return fsck_commit((struct commit *) obj);
306-
if (obj->type == TYPE_TAG)
306+
if (obj->type == OBJ_TAG)
307307
return fsck_tag((struct tag *) obj);
308308
/* By now, parse_object() would've returned NULL instead. */
309309
return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type);
@@ -472,7 +472,7 @@ static int fsck_cache_tree(struct cache_tree *it)
472472
}
473473
mark_reachable(obj, REACHABLE);
474474
obj->used = 1;
475-
if (obj->type != TYPE_TREE)
475+
if (obj->type != OBJ_TREE)
476476
err |= objerror(obj, "non-tree in cache-tree");
477477
}
478478
for (i = 0; i < it->subtree_nr; i++)

http-push.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,16 +1784,16 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
17841784

17851785
if (obj->flags & (UNINTERESTING | SEEN))
17861786
continue;
1787-
if (obj->type == TYPE_TAG) {
1787+
if (obj->type == OBJ_TAG) {
17881788
obj->flags |= SEEN;
17891789
p = add_one_object(obj, p);
17901790
continue;
17911791
}
1792-
if (obj->type == TYPE_TREE) {
1792+
if (obj->type == OBJ_TREE) {
17931793
p = process_tree((struct tree *)obj, p, NULL, name);
17941794
continue;
17951795
}
1796-
if (obj->type == TYPE_BLOB) {
1796+
if (obj->type == OBJ_BLOB) {
17971797
p = process_blob((struct blob *)obj, p, NULL, name);
17981798
continue;
17991799
}
@@ -1960,12 +1960,12 @@ static int ref_newer(const unsigned char *new_sha1,
19601960
* old. Otherwise we require --force.
19611961
*/
19621962
o = deref_tag(parse_object(old_sha1), NULL, 0);
1963-
if (!o || o->type != TYPE_COMMIT)
1963+
if (!o || o->type != OBJ_COMMIT)
19641964
return 0;
19651965
old = (struct commit *) o;
19661966

19671967
o = deref_tag(parse_object(new_sha1), NULL, 0);
1968-
if (!o || o->type != TYPE_COMMIT)
1968+
if (!o || o->type != OBJ_COMMIT)
19691969
return 0;
19701970
new = (struct commit *) o;
19711971

@@ -2044,7 +2044,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
20442044
fwrite_buffer(ref_info, 1, len, buf);
20452045
free(ref_info);
20462046

2047-
if (o->type == TYPE_TAG) {
2047+
if (o->type == OBJ_TAG) {
20482048
o = deref_tag(o, ls->dentry_name, 0);
20492049
if (o) {
20502050
len = strlen(ls->dentry_name) + 45;

name-rev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ static int name_ref(const char *path, const unsigned char *sha1)
8484
if (tags_only && strncmp(path, "refs/tags/", 10))
8585
return 0;
8686

87-
while (o && o->type == TYPE_TAG) {
87+
while (o && o->type == OBJ_TAG) {
8888
struct tag *t = (struct tag *) o;
8989
if (!t->tagged)
9090
break; /* broken repository */
9191
o = parse_object(t->tagged->sha1);
9292
deref = 1;
9393
}
94-
if (o && o->type == TYPE_COMMIT) {
94+
if (o && o->type == OBJ_COMMIT) {
9595
struct commit *commit = (struct commit *)o;
9696

9797
if (!strncmp(path, "refs/heads/", 11))
@@ -111,7 +111,7 @@ static const char* get_rev_name(struct object *o)
111111
struct rev_name *n;
112112
struct commit *c;
113113

114-
if (o->type != TYPE_COMMIT)
114+
if (o->type != OBJ_COMMIT)
115115
return "undefined";
116116
c = (struct commit *) o;
117117
n = c->util;
@@ -172,7 +172,7 @@ int main(int argc, char **argv)
172172
}
173173

174174
o = deref_tag(parse_object(sha1), *argv, 0);
175-
if (!o || o->type != TYPE_COMMIT) {
175+
if (!o || o->type != OBJ_COMMIT) {
176176
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
177177
*argv);
178178
continue;

object.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ struct object *get_indexed_object(unsigned int idx)
1919
}
2020

2121
const char *type_names[] = {
22-
"none", "blob", "tree", "commit", "bad"
22+
"none", "commit", "tree", "blob", "tag",
23+
"bad type 5", "bad type 6", "delta", "bad",
2324
};
2425

2526
static unsigned int hash_obj(struct object *obj, unsigned int n)
@@ -88,7 +89,7 @@ void created_object(const unsigned char *sha1, struct object *obj)
8889
{
8990
obj->parsed = 0;
9091
obj->used = 0;
91-
obj->type = TYPE_NONE;
92+
obj->type = OBJ_NONE;
9293
obj->flags = 0;
9394
memcpy(obj->sha1, sha1, 20);
9495

@@ -131,7 +132,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
131132
if (!obj) {
132133
union any_object *ret = xcalloc(1, sizeof(*ret));
133134
created_object(sha1, &ret->object);
134-
ret->object.type = TYPE_NONE;
135+
ret->object.type = OBJ_NONE;
135136
return &ret->object;
136137
}
137138
return obj;

object.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ struct object_array {
2424
#define TYPE_BITS 3
2525
#define FLAG_BITS 27
2626

27-
#define TYPE_NONE 0
28-
#define TYPE_BLOB 1
29-
#define TYPE_TREE 2
30-
#define TYPE_COMMIT 3
31-
#define TYPE_TAG 4
32-
#define TYPE_BAD 5
27+
/*
28+
* The object type is stored in 3 bits.
29+
*/
30+
enum object_type {
31+
OBJ_NONE = 0,
32+
OBJ_COMMIT = 1,
33+
OBJ_TREE = 2,
34+
OBJ_BLOB = 3,
35+
OBJ_TAG = 4,
36+
/* 5/6 for future expansion */
37+
OBJ_DELTA = 7,
38+
OBJ_BAD,
39+
};
3340

3441
struct object {
3542
unsigned parsed : 1;
@@ -40,14 +47,14 @@ struct object {
4047
};
4148

4249
extern int track_object_refs;
43-
extern const char *type_names[];
50+
extern const char *type_names[9];
4451

4552
extern unsigned int get_max_object_index(void);
4653
extern struct object *get_indexed_object(unsigned int);
4754

4855
static inline const char *typename(unsigned int type)
4956
{
50-
return type_names[type > TYPE_TAG ? TYPE_BAD : type];
57+
return type_names[type > OBJ_BAD ? OBJ_BAD : type];
5158
}
5259

5360
extern struct object_refs *lookup_object_refs(struct object *);

pack.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
#ifndef PACK_H
22
#define PACK_H
33

4-
/*
5-
* The packed object type is stored in 3 bits.
6-
* The type value 0 is a reserved prefix if ever there is more than 7
7-
* object types, or any future format extensions.
8-
*/
9-
enum object_type {
10-
OBJ_EXT = 0,
11-
OBJ_COMMIT = 1,
12-
OBJ_TREE = 2,
13-
OBJ_BLOB = 3,
14-
OBJ_TAG = 4,
15-
/* 5/6 for future expansion */
16-
OBJ_DELTA = 7,
17-
};
4+
#include "object.h"
185

196
/*
207
* Packed object header

0 commit comments

Comments
 (0)