9 /* the delta object definition (it can alias any other object) */
20 struct delta *lookup_delta(unsigned char *sha1)
22 struct object *obj = lookup_object(sha1);
24 struct delta *ret = xmalloc(sizeof(struct delta));
25 memset(ret, 0, sizeof(struct delta));
26 created_object(sha1, &ret->u.object);
29 return (struct delta *) obj;
32 int parse_delta_buffer(struct delta *item, void *buffer, unsigned long size)
34 struct object *reference;
35 struct object_list *p;
37 if (item->u.object.delta)
39 item->u.object.delta = 1;
42 reference = lookup_object(buffer);
44 struct delta *ref = xmalloc(sizeof(struct delta));
45 memset(ref, 0, sizeof(struct delta));
46 created_object(buffer, &ref->u.object);
47 reference = &ref->u.object;
50 p = xmalloc(sizeof(*p));
51 p->item = &item->u.object;
52 p->next = reference->attached_deltas;
53 reference->attached_deltas = p;
57 int process_deltas(void *src, unsigned long src_size, const char *src_type,
58 struct object_list *delta_list)
62 struct object *obj = delta_list->item;
64 void *map, *delta, *buf;
65 unsigned long map_size, delta_size, buf_size;
66 map = map_sha1_file(obj->sha1, &map_size);
69 delta = unpack_sha1_file(map, map_size, type, &delta_size);
70 munmap(map, map_size);
73 if (strcmp(type, "delta") || delta_size <= 20) {
77 buf = patch_delta(src, src_size,
78 delta+20, delta_size-20,
83 if (check_sha1_signature(obj->sha1, buf, buf_size, src_type) < 0)
84 printf("sha1 mismatch for delta %s\n", sha1_to_hex(obj->sha1));
85 if (obj->type && obj->type != src_type) {
86 error("got %s when expecting %s for delta %s",
87 src_type, obj->type, sha1_to_hex(obj->sha1));
92 if (src_type == blob_type) {
93 parse_blob_buffer((struct blob *)obj, buf, buf_size);
94 } else if (src_type == tree_type) {
95 parse_tree_buffer((struct tree *)obj, buf, buf_size);
96 } else if (src_type == commit_type) {
97 parse_commit_buffer((struct commit *)obj, buf, buf_size);
98 } else if (src_type == tag_type) {
99 parse_tag_buffer((struct tag *)obj, buf, buf_size);
101 error("unknown object type %s", src_type);
105 if (obj->attached_deltas) {
106 int depth = process_deltas(buf, buf_size, src_type,
107 obj->attached_deltas);
112 } while ((delta_list = delta_list->next));