pack-objects: avoid delta chains that are too long.
This tries to rework the solution for the excess delta chain problem. An earlier commit worked it around ``cheaply'', but repeated repacking risks unbound growth of delta chains. This version counts the length of delta chain we are reusing from the existing pack, and makes sure a base object that has sufficiently long delta chain does not get deltified. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 17, 2006 at 20:58 UTC
e4c9327a77bd59e85d4b17a612e78977d68773ee
1 file changed
+35
-8
pack-objects.c
+35
-8
@@ -10,16 +10,22 @@ static const char pack_usage[] = "git-pack-objects [-q] [--no-reuse-delta] [--no
10
struct object_entry {
11
unsigned char sha1[20];
12
unsigned long size; /* uncompressed size */
13
- unsigned long offset; /* offset into the final pack file (nonzero if already written) */
13
+ unsigned long offset; /* offset into the final pack file;
14
+ * nonzero if already written.
15
+ */
16
unsigned int depth; /* delta depth */
17
+ unsigned int delta_limit; /* base adjustment for in-pack delta */
18
unsigned int hash; /* name hint hash */
19
enum object_type type;
17
- unsigned char edge; /* reused delta chain points at this entry. */
20
enum object_type in_pack_type; /* could be delta */
21
unsigned long delta_size; /* delta data size (uncompressed) */
22
struct object_entry *delta; /* delta base object */
23
struct packed_git *in_pack; /* already in pack */
24
unsigned int in_pack_offset;
25
+ struct object_entry *delta_child; /* delitified objects who bases me */
26
+ struct object_entry *delta_sibling; /* other deltified objects who
27
+ * uses the same base as me
28
+ */
29
};
30
31
/*
@@ -470,7 +476,8 @@ static void check_object(struct object_entry *entry)
476
entry->delta = base_entry;
477
entry->type = OBJ_DELTA;
478
473
- base_entry->edge = 1;
479
+ entry->delta_sibling = base_entry->delta_child;
480
+ base_entry->delta_child = entry;
481
482
return;
483
}
@@ -513,15 +520,32 @@ static void hash_objects(void)
520
}
521
}
522
523
+static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
524
+{
525
+ struct object_entry *child = me->delta_child;
526
+ unsigned int m = n;
527
+ while (child) {
528
+ unsigned int c = check_delta_limit(child, n + 1);
529
+ if (m < c)
530
+ m = c;
531
+ child = child->delta_sibling;
532
+ }
533
+ return m;
534
+}
535
+
536
static void get_object_details(void)
537
{
538
int i;
519
- struct object_entry *entry = objects;
539
+ struct object_entry *entry;
540
541
hash_objects();
542
prepare_pack_ix();
523
- for (i = 0; i < nr_objects; i++)
524
- check_object(entry++);
543
+ for (i = 0, entry = objects; i < nr_objects; i++, entry++)
544
+ check_object(entry);
545
+ for (i = 0, entry = objects; i < nr_objects; i++, entry++)
546
+ if (!entry->delta && entry->delta_child)
547
+ entry->delta_limit =
548
+ check_delta_limit(entry, 1);
549
}
550
551
typedef int (*entry_sort_t)(const struct object_entry *, const struct object_entry *);
@@ -598,8 +622,11 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
622
* that depend on the current object into account -- otherwise
623
* they would become too deep.
624
*/
601
- if (cur_entry->edge)
602
- max_depth /= 4;
625
+ if (cur_entry->delta_child) {
626
+ if (max_depth <= cur_entry->delta_limit)
627
+ return 0;
628
+ max_depth -= cur_entry->delta_limit;
629
+ }
630
631
size = cur_entry->size;
632
if (size < 50)