10 /* the delta object definition (it can alias any other object) */
21 struct delta
*lookup_delta(unsigned char *sha1
)
23 struct object
*obj
= lookup_object(sha1
);
25 struct delta
*ret
= xmalloc(sizeof(struct delta
));
26 memset(ret
, 0, sizeof(struct delta
));
27 created_object(sha1
, &ret
->u
.object
);
30 return (struct delta
*) obj
;
33 int parse_delta_buffer(struct delta
*item
, void *buffer
, unsigned long size
)
35 struct object
*reference
;
36 struct object_list
*p
;
38 if (item
->u
.object
.delta
)
40 item
->u
.object
.delta
= 1;
43 reference
= lookup_object(buffer
);
45 struct delta
*ref
= xmalloc(sizeof(struct delta
));
46 memset(ref
, 0, sizeof(struct delta
));
47 created_object(buffer
, &ref
->u
.object
);
48 reference
= &ref
->u
.object
;
51 p
= xmalloc(sizeof(*p
));
52 p
->item
= &item
->u
.object
;
53 p
->next
= reference
->attached_deltas
;
54 reference
->attached_deltas
= p
;
58 int process_deltas(void *src
, unsigned long src_size
, const char *src_type
,
59 struct object_list
*delta_list
)
63 struct object
*obj
= delta_list
->item
;
65 void *map
, *delta
, *buf
;
66 unsigned long map_size
, delta_size
, buf_size
;
67 map
= map_sha1_file(obj
->sha1
, &map_size
);
70 delta
= unpack_sha1_file(map
, map_size
, type
, &delta_size
);
71 munmap(map
, map_size
);
74 if (strcmp(type
, "delta") || delta_size
<= 20) {
78 buf
= patch_delta(src
, src_size
,
79 delta
+20, delta_size
-20,
84 if (check_sha1_signature(obj
->sha1
, buf
, buf_size
, src_type
) < 0)
85 printf("sha1 mismatch for delta %s\n", sha1_to_hex(obj
->sha1
));
86 if (obj
->type
&& obj
->type
!= src_type
) {
87 error("got %s when expecting %s for delta %s",
88 src_type
, obj
->type
, sha1_to_hex(obj
->sha1
));
93 if (src_type
== blob_type
) {
94 parse_blob_buffer((struct blob
*)obj
, buf
, buf_size
);
95 } else if (src_type
== tree_type
) {
96 parse_tree_buffer((struct tree
*)obj
, buf
, buf_size
);
97 } else if (src_type
== commit_type
) {
98 parse_commit_buffer((struct commit
*)obj
, buf
, buf_size
);
99 } else if (src_type
== tag_type
) {
100 parse_tag_buffer((struct tag
*)obj
, buf
, buf_size
);
102 error("unknown object type %s", src_type
);
106 if (obj
->attached_deltas
) {
107 int depth
= process_deltas(buf
, buf_size
, src_type
,
108 obj
->attached_deltas
);
113 } while ((delta_list
= delta_list
->next
));