🌐 AI搜索 & 代理 主页
blob: b6618d92bf04d549350d83b6237770c48734686f [file] [log] [blame]
Daniel Barkalow6eb8ae02005-04-18 18:39:481#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-20 00:42:359struct 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 16:43:5815 unsigned mode;
Linus Torvalds1f1e8952006-06-20 00:42:3516 } *objects;
17};
18
Thiago Farina3cd47452010-08-29 02:04:1719#define OBJECT_ARRAY_INIT { 0, 0, NULL }
20
Linus Torvalds885a86a2006-06-14 23:45:1321#define TYPE_BITS 3
22#define FLAG_BITS 27
23
Linus Torvalds19746322006-07-12 03:45:3124/*
25 * The object type is stored in 3 bits.
26 */
Daniel Barkalow6eb8ae02005-04-18 18:39:4827struct object {
28 unsigned parsed : 1;
29 unsigned used : 1;
Linus Torvalds885a86a2006-06-14 23:45:1330 unsigned type : TYPE_BITS;
31 unsigned flags : FLAG_BITS;
Daniel Barkalow6eb8ae02005-04-18 18:39:4832 unsigned char sha1[20];
Daniel Barkalow6eb8ae02005-04-18 18:39:4833};
34
Nicolas Pitredf843662007-02-26 19:55:5835extern const char *typename(unsigned int type);
36extern int type_from_string(const char *str);
Linus Torvalds885a86a2006-06-14 23:45:1337
Linus Torvaldsfc046a72006-06-30 04:38:5538extern unsigned int get_max_object_index(void);
39extern struct object *get_indexed_object(unsigned int);
Linus Torvalds3e4339e2006-06-18 18:45:0240
Junio C Hamano628b06d2008-09-10 19:22:3541/*
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 15:05:3953struct object *lookup_object(const unsigned char *sha1);
Daniel Barkalow6eb8ae02005-04-18 18:39:4854
Linus Torvalds100c5f32007-04-17 05:11:4355extern void *create_object(const unsigned char *sha1, int type, void *obj);
Daniel Barkalow6eb8ae02005-04-18 18:39:4856
Daniel Barkalowe9eefa62005-04-28 14:46:3357/** Returns the object, having parsed it to find out what it is. **/
Jason McMullan5d6ccf52005-06-03 15:05:3958struct object *parse_object(const unsigned char *sha1);
Daniel Barkalowe9eefa62005-04-28 14:46:3359
Junio C Hamano9f613dd2006-09-15 20:30:0260/* 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 19:55:5964struct 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 20:30:0265
barkalow@iabervon.org66e481b2005-08-02 23:45:4866/** Returns the object, with potentially excess memory allocated. **/
67struct object *lookup_unknown_object(const unsigned char *sha1);
68
Junio C Hamanoa6080a02007-06-07 07:04:0169struct object_list *object_list_insert(struct object *item,
barkalow@iabervon.org66e481b2005-08-02 23:45:4870 struct object_list **list_p);
71
barkalow@iabervon.org66e481b2005-08-02 23:45:4872int object_list_contains(struct object_list *list, struct object *obj);
73
Linus Torvalds1f1e8952006-06-20 00:42:3574/* Object array handling .. */
75void add_object_array(struct object *obj, const char *name, struct object_array *array);
Martin Koeglere5709a42007-04-22 16:43:5876void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
Junio C Hamanob2a6d1c2009-01-18 06:27:0877void object_array_remove_duplicates(struct object_array *);
Linus Torvalds1f1e8952006-06-20 00:42:3578
Daniel Barkalow6eb8ae02005-04-18 18:39:4879#endif /* OBJECT_H */