10 static int find_object(unsigned char *sha1)
12 int first = 0, last = nr_objs;
14 while (first < last) {
15 int next = (first + last) / 2;
16 struct object *obj = objs[next];
19 cmp = memcmp(sha1, obj->sha1, 20);
31 struct object *lookup_object(unsigned char *sha1)
33 int pos = find_object(sha1);
39 void created_object(unsigned char *sha1, struct object *obj)
41 int pos = find_object(sha1);
44 memcpy(obj->sha1, sha1, 20);
50 die("Inserting %s twice\n", sha1_to_hex(sha1));
53 if (obj_allocs == nr_objs) {
54 obj_allocs = alloc_nr(obj_allocs);
55 objs = realloc(objs, obj_allocs * sizeof(struct object *));
58 /* Insert it into the right place */
59 memmove(objs + pos + 1, objs + pos, (nr_objs - pos) *
60 sizeof(struct object *));
66 void add_ref(struct object *refer, struct object *target)
68 struct object_list **pp = &refer->refs;
69 struct object_list *p;
71 while ((p = *pp) != NULL) {
72 if (p->item == target)
78 p = malloc(sizeof(*p));
84 void mark_reachable(struct object *obj, unsigned int mask)
86 struct object_list *p = obj->refs;
88 /* If we've been here already, don't bother */
89 if (obj->flags & mask)
93 mark_reachable(p->item, mask);