blob: 6a97b6ba1a43e1d38eb07515ad298e0067628127 [file] [log] [blame]
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -07001#ifndef OBJECT_H
2#define OBJECT_H
3
4struct object_list {
5 struct object *item;
6 struct object_list *next;
7};
8
Linus Torvalds1f1e8952006-06-19 17:42:35 -07009struct object_array {
10 unsigned int nr;
11 unsigned int alloc;
12 struct object_array_entry {
13 struct object *item;
14 const char *name;
Martin Koeglere5709a42007-04-22 18:43:58 +020015 unsigned mode;
Linus Torvalds1f1e8952006-06-19 17:42:35 -070016 } *objects;
17};
18
Thiago Farina3cd47452010-08-28 23:04:17 -030019#define OBJECT_ARRAY_INIT { 0, 0, NULL }
20
Linus Torvalds885a86a2006-06-14 16:45:13 -070021#define TYPE_BITS 3
22#define FLAG_BITS 27
23
Linus Torvalds19746322006-07-11 20:45:31 -070024/*
25 * The object type is stored in 3 bits.
26 */
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070027struct object {
28 unsigned parsed : 1;
29 unsigned used : 1;
Linus Torvalds885a86a2006-06-14 16:45:13 -070030 unsigned type : TYPE_BITS;
31 unsigned flags : FLAG_BITS;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070032 unsigned char sha1[20];
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070033};
34
Nicolas Pitredf843662007-02-26 14:55:58 -050035extern const char *typename(unsigned int type);
36extern int type_from_string(const char *str);
Linus Torvalds885a86a2006-06-14 16:45:13 -070037
Linus Torvaldsfc046a72006-06-29 21:38:55 -070038extern unsigned int get_max_object_index(void);
39extern struct object *get_indexed_object(unsigned int);
Linus Torvalds3e4339e2006-06-18 11:45:02 -070040
Junio C Hamano628b06d2008-09-10 12:22:35 -070041/*
42 * This can be used to see if we have heard of the object before, but
43 * it can return "yes we have, and here is a half-initialised object"
44 * for an object that we haven't loaded/parsed yet.
45 *
46 * When parsing a commit to create an in-core commit object, its
47 * parents list holds commit objects that represent its parents, but
48 * they are expected to be lazily initialized and do not know what
49 * their trees or parents are yet. When this function returns such a
50 * half-initialised objects, the caller is expected to initialize them
51 * by calling parse_object() on them.
52 */
Jason McMullan5d6ccf52005-06-03 11:05:39 -040053struct object *lookup_object(const unsigned char *sha1);
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070054
Linus Torvalds100c5f32007-04-16 22:11:43 -070055extern void *create_object(const unsigned char *sha1, int type, void *obj);
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070056
Daniel Barkalowe9eefa62005-04-28 07:46:33 -070057/** Returns the object, having parsed it to find out what it is. **/
Jason McMullan5d6ccf52005-06-03 11:05:39 -040058struct object *parse_object(const unsigned char *sha1);
Daniel Barkalowe9eefa62005-04-28 07:46:33 -070059
Junio C Hamano9f613dd2006-09-15 13:30:02 -070060/* Given the result of read_sha1_file(), returns the object after
61 * parsing it. eaten_p indicates if the object has a borrowed copy
62 * of buffer and the caller should not free() it.
63 */
Nicolas Pitre21666f12007-02-26 14:55:59 -050064struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
Junio C Hamano9f613dd2006-09-15 13:30:02 -070065
barkalow@iabervon.org66e481b2005-08-02 19:45:48 -040066/** Returns the object, with potentially excess memory allocated. **/
67struct object *lookup_unknown_object(const unsigned char *sha1);
68
Junio C Hamanoa6080a02007-06-07 00:04:01 -070069struct object_list *object_list_insert(struct object *item,
barkalow@iabervon.org66e481b2005-08-02 19:45:48 -040070 struct object_list **list_p);
71
barkalow@iabervon.org66e481b2005-08-02 19:45:48 -040072int object_list_contains(struct object_list *list, struct object *obj);
73
Linus Torvalds1f1e8952006-06-19 17:42:35 -070074/* Object array handling .. */
75void add_object_array(struct object *obj, const char *name, struct object_array *array);
Martin Koeglere5709a42007-04-22 18:43:58 +020076void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
Junio C Hamanob2a6d1c2009-01-17 22:27:08 -080077void object_array_remove_duplicates(struct object_array *);
Linus Torvalds1f1e8952006-06-19 17:42:35 -070078
Heiko Voigtbcc0a3e2012-03-29 09:21:21 +020079void clear_object_flags(unsigned flags);
80
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070081#endif /* OBJECT_H */