ref: 849b875b7d8157b080840fcdcfb7398cdbc8fbe3
parent: 137053f83a65f32de2e8a29c1e635391decbbb37
author: Ori Bernstein <ori@eigenstate.org>
date: Sun May 10 22:32:41 EDT 2020
clean up flow through pack.c should be functionally identical
--- a/pack.c
+++ b/pack.c
@@ -62,7 +62,7 @@
if(!o)
return;
o->refs--;
- if(!o->refs)
+ if(o->refs == 0)
clear(o);
}
@@ -371,10 +371,8 @@
goto error;
if((b = readidxobject(f, h, flag)) == nil)
goto error;
- ref(b);
if(applydelta(o, b, d, n) == -1)
goto error;
- unref(b);
free(d);
return 0;
error:
@@ -976,7 +974,7 @@
}
if(i % step == 0)
fprint(2, ".");
- if(!objects[i]){
+ if(objects[i] == nil){
o = emalloc(sizeof(Object));
o->off = Boffset(f);
objects[i] = o;
@@ -983,12 +981,15 @@
}
o = objects[i];
Bseek(f, o->off, 0);
- if (readpacked(f, o, Cidx) == 0){
- sha1((uchar*)o->all, o->size + strlen(o->all) + 1, o->hash.h, nil);
- cache(o);
- valid[i] = 1;
- n++;
+ if (readpacked(f, o, Cidx) == -1){
+ objects[i] = nil;
+ free(o);
+ continue;
}
+ sha1((uchar*)o->all, o->size + strlen(o->all) + 1, o->hash.h, nil);
+ valid[i] = 1;
+ cache(o);
+ n++;
if(objectcrc(f, o) == -1)
return -1;
}