ref: 738c1ea8ac43ffcb5589ad1fe749b8f13fc4a652
parent: 94c13f98027ccd52343168e5af279028a403b1fc
author: Ori Bernstein <[email protected]>
date: Fri Sep 25 10:11:05 EDT 2020
deltify: limit delta chain length. We don't want insanely long delta chains, for a number of reasons. Upstream git limits them to 4095, we should do the same.
--- a/pack.c
+++ b/pack.c
@@ -9,16 +9,19 @@
typedef struct Compout Compout;
struct Objmeta {
+ /* For sorting */
int type;
char *path;
vlong mtime;
Hash hash;
- Dtab tab;
+ /* The best delta we picked */
Object *obj;
Object *base;
Delta *delta;
int ndelta;
+ int nchain;
+
Dtab dtab;
};
@@ -1282,16 +1285,25 @@
m->ndelta = 0;
dtinit(&m->dtab, a->data, a->size);
for(; p != m; p++){
+ /* lets not make the chains too long */
+ if(p->nchain >= 4095)
+ continue;
if((b = readobject(p->hash)) == nil)
sysfatal("missing object %H", p->hash);
d = deltify(a->data, a->size, &p->dtab, &nd);
sz = deltasz(d, nd);
if(sz + 32 < best){
+ /*
+ * if we already picked a best delta,
+ * replace it.
+ */
free(m->delta);
best = sz;
m->base = b;
m->delta = d;
m->ndelta = nd;
+ m->nchain = p->nchain + 1;
+
}else
free(d);
unref(b);