+static void expand_deltas(void)
+{
+ int i, max_depth = 0;
+
+ /*
+ * To be as efficient as possible we look for delta heads and
+ * recursively process them going backward, and parsing
+ * resulting objects along the way. This allows for processing
+ * each delta objects only once regardless of the delta depth.
+ */
+ for (i = 0; i < nr_objs; i++) {
+ struct object *obj = objs[i];
+ if (obj->parsed && !obj->delta && obj->attached_deltas) {
+ int depth = 0;
+ char type[10];
+ unsigned long size;
+ void *buf = read_sha1_file(obj->sha1, type, &size);
+ if (!buf)
+ continue;
+ depth = process_deltas(buf, size, obj->type,
+ obj->attached_deltas);
+ if (max_depth < depth)
+ max_depth = depth;
+ }
+ }
+ if (show_max_delta_depth)
+ printf("maximum delta depth = %d\n", max_depth);
+}
+