ref: b4838c1b5b5e07ca01e9644cbd55fc5b40116a6e
parent: 5add783e89fad10069df63ef4314affb6d002b61
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Dec 5 13:18:38 EST 2020
git/serve: remove percent progress in logs. git/serve used to show percent progress from pack operations no matter what, which meant we were dumping a bunch of crap into the logs; refactor the percentage printing, and then turn it off in git/serve.
--- a/git.h
+++ b/git.h
@@ -226,6 +226,7 @@
extern Hash Zhash;
extern int chattygit;
extern int cachemax;
+extern int interactive;
#pragma varargck type "H" Hash
#pragma varargck type "T" int
@@ -280,6 +281,7 @@
int swapsuffix(char *, int, char *, char *, char *);
char *strip(char *);
int findrepo(char *, int);
+int showprogress(int, int);
/* packing */
void dtinit(Dtab *, void *, int);
--- a/pack.c
+++ b/pack.c
@@ -1004,7 +1004,7 @@
{
char hdr[4*3], buf[8];
int nobj, npct, nvalid, nbig;
- int i, n, r, x, pcnt;
+ int i, n, r, pct;
Object *o, **objects;
DigestState *st;
char *valid;
@@ -1023,26 +1023,22 @@
return -1;
}
+ pct = 0;
npct = 0;
nvalid = 0;
nobj = GETBE32(hdr + 8);
objects = calloc(nobj, sizeof(Object*));
valid = calloc(nobj, sizeof(char));
- fprint(2, "indexing %d objects: 0%%", nobj);
+ if(interactive)
+ fprint(2, "indexing %d objects: 0%%", nobj);
while(nvalid != nobj){
n = 0;
- pcnt = 0;
for(i = 0; i < nobj; i++){
- x = (npct*100) / nobj;
if(valid[i]){
n++;
continue;
}
- if(x > pcnt){
- pcnt = x;
- if(pcnt%10 == 0)
- fprint(2, "\b\b\b\b%3d%%", pcnt);
- }
+ pct = showprogress((npct*100)/nobj, pct);
if(objects[i] == nil){
o = emalloc(sizeof(Object));
o->off = Boffset(f);
@@ -1289,21 +1285,15 @@
Objmeta *m, *p;
Object *a, *b;
Delta *d;
- int i, j, x, nd, sz, pcnt, best;
+ int i, j, nd, sz, pct, best;
- pcnt = 0;
+ pct = 0;
dprint(1, "picking deltas\n");
- if(interactive)
- fprint(2, "deltifying %d objects: 0%%", nmeta);
+ fprint(2, "deltifying %d objects: 0%%", nmeta);
qsort(meta, nmeta, sizeof(Objmeta*), deltaordercmp);
for(i = 0; i < nmeta; i++){
m = meta[i];
- x = (i*100) / nmeta;
- if(interactive && x > pcnt){
- pcnt = x;
- if(pcnt%10 == 0)
- fprint(2, "\b\b\b\b%3d%%", pcnt);
- }
+ pct = showprogress((i*100) / nmeta, pct);
if((a = readobject(m->obj->hash)) == nil)
sysfatal("readobject %H: %r", m->obj->hash);
best = a->size;
@@ -1503,7 +1493,7 @@
static int
genpack(int fd, Objmeta **meta, int nmeta, Hash *h, int odelta)
{
- int i, nh, nd, x, res, pcnt, ret;
+ int i, nh, nd, res, pct, ret;
DigestState *st;
Biobuf *bfd;
Objmeta *m;
@@ -1512,7 +1502,8 @@
st = nil;
ret = -1;
- pcnt = 0;
+ pct = 0;
+ dprint(1, "generating pack\n");
if((fd = dup(fd, -1)) == -1)
return -1;
if((bfd = Bfdopen(fd, OWRITE)) == nil)
@@ -1526,15 +1517,11 @@
if(hwrite(bfd, buf, 4, &st) == -1)
return -1;
qsort(meta, nmeta, sizeof(Objmeta*), writeordercmp);
- fprint(2, "writing %d objects: 0%%", nmeta);
+ if(interactive)
+ fprint(2, "writing %d objects: 0%%", nmeta);
for(i = 0; i < nmeta; i++){
m = meta[i];
- x = (i*100) / nmeta;
- if(x > pcnt){
- pcnt = x;
- if(pcnt%10 == 0)
- fprint(2, "\b\b\b\b%3d%%", pcnt);
- }
+ pct = showprogress((i*100)/nmeta, pct);
if((o = readobject(m->obj->hash)) == nil)
return -1;
if(m->delta == nil){
@@ -1584,7 +1571,6 @@
if(nmeta == 0)
return 0;
pickdeltas(meta, nmeta);
- dprint(1, "generating pack\n");
r = genpack(fd, meta, nmeta, h, 0);
for(i = 0; i < nmeta; i++)
freemeta(meta[i]);
--- a/serve.c
+++ b/serve.c
@@ -479,6 +479,7 @@
gitinit();
user = "none";
+ interactive = 0;
if(allowwrite)
user = getuser();
if(newns(user, namespace) == -1)
--- a/util.c
+++ b/util.c
@@ -8,7 +8,7 @@
Hash Zhash;
int chattygit;
-int hidepct;
+int interactive = 1;
Object*
emptydir(void)
@@ -308,4 +308,16 @@
}
werrstr("not a git repository");
return -1;
+}
+
+int
+showprogress(int x, int pct)
+{
+ if(!interactive)
+ return 0;
+ if(x > pct){
+ pct = x;
+ fprint(1, "\b\b\b\b%3d%%", pct);
+ }
+ return pct;
}