ref: 30f251641bc3be46341341f435f06a9d927b591f
parent: d257e6478745710e03fa8699bc0b367bf7c0b8e8
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 6 19:49:03 EDT 2021
utils: avoid uninterruptible temporary dont' fall into the rathole.
--- a/fetch.c
+++ b/fetch.c
@@ -228,8 +228,13 @@
req = 1;
}
flushpkt(c);
+ if(resolveref(&h, "HEAD") != -1){
+ n = snprint(buf, sizeof(buf), "have %H\n", h);
+ if(writepkt(c, buf, n + 1) == -1)
+ sysfatal("could not send have for %H", have[i]);
+ }
for(i = 0; i < nref; i++){
- if(hasheq(&have[i], &Zhash))
+ if(hasheq(&have[i], &Zhash) || hasheq(&have[i], &h))
continue;
n = snprint(buf, sizeof(buf), "have %H\n", have[i]);
if(writepkt(c, buf, n + 1) == -1)
--- a/pack.c
+++ b/pack.c
@@ -1000,7 +1000,8 @@
retried = 0;
retry:
for(i = 0; i < npackf; i++){
- if((o = searchindex(packf[i].idx, packf[i].nidx, h)) != -1){
+ o = searchindex(packf[i].idx, packf[i].nidx, h);
+ if(o != -1){
if((f = openpack(&packf[i])) == nil)
goto error;
if((r = Bseek(f, o, 0)) != -1)
--- a/util.c
+++ b/util.c
@@ -67,7 +67,8 @@
uvlong na;
void *v;
- if((na = (uvlong)n*(uvlong)sz) >= (1ULL<<30))
+ na = (uvlong)n*(uvlong)sz;
+ if(na >= (1ULL<<30))
sysfatal("alloc: overflow");
v = mallocz(na, 1);
if(v == nil)
@@ -94,7 +95,8 @@
uvlong na;
void *v;
- if((na = (uvlong)n*(uvlong)sz) >= (1ULL<<30))
+ na = (uvlong)n*(uvlong)sz;
+ if(na >= (1ULL<<30))
sysfatal("alloc: overflow");
v = realloc(p, na);
if(v == nil)