ref: b18f03aaf704b2788c60bd6a3f3ac82db85f4ec3
parent: 32d0c36db869b89a8d7d2669cc3d05a72e8025ce
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Sep 4 20:07:10 EDT 2020
deltificatioin: fix betwixt function We were requeueing objects, leading to ridiculous (exponential?) time to generate new packs when we had complex histories. This brings it down to normal times.
--- a/delta.c
+++ b/delta.c
@@ -192,5 +192,6 @@
}
emitdelta(&d, &nd, 0, l - tp, tp + ntarg - l);
*pnd = nd;
+ free(b);
return d;
}
--- a/pack.c
+++ b/pack.c
@@ -1142,12 +1142,19 @@
*m = erealloc(*m, (*nm + 1)*sizeof(Objmeta));
memset(&(*m)[*nm], 0, sizeof(Objmeta));
(*m)[*nm].type = type;
- (*m)[*nm].path = path;
+ (*m)[*nm].path = estrdup(path);
(*m)[*nm].mtime = mtime;
(*m)[*nm].hash = h;
*nm += 1;
}
+static void
+freemeta(Objmeta *m)
+{
+ free(m->delta);
+ free(m->path);
+}
+
static int
loadtree(Objmeta **m, int *nm, Hash tree, char *dpath, vlong mtime, Objset *has)
{
@@ -1174,8 +1181,11 @@
if(k == GBlob){
osadd(has, o);
addmeta(m, nm, k, o->hash, p, mtime);
- }else if(loadtree(m, nm, e->h, p, mtime, has) == -1)
+ }else if(loadtree(m, nm, e->h, p, mtime, has) == -1){
+ free(p);
return -1;
+ }
+ free(p);
}
unref(t);
return 0;
@@ -1192,7 +1202,7 @@
if((c = readobject(h)) == nil)
return -1;
osadd(has, c);
- addmeta(m, nm, c->type, c->hash, estrdup(""), c->commit->ctime);
+ addmeta(m, nm, c->type, c->hash, "", c->commit->ctime);
r = loadtree(m, nm, c->commit->tree, "", c->commit->ctime, has);
unref(c);
return r;
@@ -1482,7 +1492,7 @@
writepack(int fd, Object **obj, int nobj, Hash *h)
{
Objmeta *meta;
- int nmeta;
+ int i, r, nmeta;
dprint(1, "reading meta\n");
if((nmeta = readmeta(obj, nobj, &meta)) == -1)
@@ -1490,9 +1500,9 @@
dprint(1, "picking deltas\n");
pickdeltas(meta, nmeta);
dprint(1, "generating pack\n");
- if(genpack(fd, meta, nmeta, h) == -1){
- free(meta);
- return -1;
- }
- return 0;
+ r = genpack(fd, meta, nmeta, h);
+ for(i = 0; i < nmeta; i++)
+ freemeta(&meta[i]);
+ free(meta);
+ return r;
}
--- a/ref.c
+++ b/ref.c
@@ -254,7 +254,7 @@
Objq *q, *e, *n, **p;
Objset keep, drop;
Object *o, *c;
- int i;
+ int i, ncolor;
e = nil;
q = nil;
@@ -287,12 +287,17 @@
dprint(1, "finding twixt commits\n");
while(q != nil){
if(oshas(&drop, q->o->hash))
+ ncolor = Drop;
+ else if(oshas(&keep, q->o->hash))
+ ncolor = Keep;
+ else
+ ncolor = Blank;
+ if(ncolor == Drop || ncolor == Keep && q->color == Keep)
goto next;
-
- if(oshas(&keep, q->o->hash) && q->color == Drop){
+ if(ncolor == Keep && q->color == Drop){
if(repaint(&keep, &drop, q->o) == -1)
goto error;
- }else{
+ }else if (ncolor == Blank) {
dprint(2, "visit: %s %H\n", q->color == Keep ? "keep" : "drop", q->o->hash);
if(q->color == Keep)
osadd(&keep, q->o);
@@ -310,6 +315,8 @@
e = n;
unref(c);
}
+ }else{
+ sysfatal("oops");
}
next:
n = q->next;
@@ -597,6 +604,7 @@
noref: free(name);
next: free(path);
}
+ free(dir);
return 0;
}
--- a/util.c
+++ b/util.c
@@ -67,7 +67,7 @@
v = realloc(p, n);
if(v == nil)
sysfatal("realloc: %r");
- setmalloctag(v, getcallerpc(&n));
+ setmalloctag(v, getcallerpc(&p));
return v;
}