Shrink "struct object" a bit
[git/git.git] / object.h
CommitLineData
6eb8ae00
DB
1#ifndef OBJECT_H
2#define OBJECT_H
3
4struct object_list {
5 struct object *item;
6 struct object_list *next;
9ce43d1c 7 const char *name;
6eb8ae00
DB
8};
9
27dedf0c
JH
10struct object_refs {
11 unsigned count;
8f1d2e6f 12 struct object *ref[FLEX_ARRAY]; /* more */
27dedf0c
JH
13};
14
885a86ab
LT
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
6eb8ae00
DB
25struct object {
26 unsigned parsed : 1;
27 unsigned used : 1;
885a86ab
LT
28 unsigned type : TYPE_BITS;
29 unsigned flags : FLAG_BITS;
6eb8ae00 30 unsigned char sha1[20];
27dedf0c 31 struct object_refs *refs;
a3437b8c 32 void *util;
6eb8ae00
DB
33};
34
8805ccac 35extern int track_object_refs;
070879ca 36extern int obj_allocs;
88355048 37extern struct object **objs;
885a86ab
LT
38extern const char *type_names[];
39
40static inline const char *typename(unsigned int type)
41{
42 return type_names[type > TYPE_TAG ? TYPE_BAD : type];
43}
6eb8ae00 44
89e4202f 45/** Internal only **/
5d6ccf5c 46struct object *lookup_object(const unsigned char *sha1);
6eb8ae00 47
89e4202f
DB
48/** Returns the object, having looked it up as being the given type. **/
49struct object *lookup_object_type(const unsigned char *sha1, const char *type);
50
5d6ccf5c 51void created_object(const unsigned char *sha1, struct object *obj);
6eb8ae00 52
e9eefa67 53/** Returns the object, having parsed it to find out what it is. **/
5d6ccf5c 54struct object *parse_object(const unsigned char *sha1);
e9eefa67 55
66e481b0
DB
56/** Returns the object, with potentially excess memory allocated. **/
57struct object *lookup_unknown_object(const unsigned char *sha1);
58
27dedf0c
JH
59struct object_refs *alloc_object_refs(unsigned count);
60void set_object_refs(struct object *obj, struct object_refs *refs);
6eb8ae00
DB
61
62void mark_reachable(struct object *obj, unsigned int mask);
63
66e481b0
DB
64struct object_list *object_list_insert(struct object *item,
65 struct object_list **list_p);
66
680bab3d
DB
67void object_list_append(struct object *item,
68 struct object_list **list_p);
69
66e481b0
DB
70unsigned object_list_length(struct object_list *list);
71
72int object_list_contains(struct object_list *list, struct object *obj);
73
6eb8ae00 74#endif /* OBJECT_H */