commit - 4b20c923ed76cf3ecc2bdb6f48005e19399474ce
commit + cf8755741988f98f8bf86bb0a99fce43a84aa389
blob - df6957508517fc33ebb458e597795c59ffa49898
blob + ead1b056ec197616b02145e138f74d76c1fef6f0
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
int
flushpkt(int fd)
{
- if(chattygit)
+ if (chattygit)
fprintf(stderr, "writepkt: 0000\n");
return write(fd, "0000", 4);
}
char *e;
int n, r;
- if(readn(fd, len, 4) == -1){
+ if (readn(fd, len, 4) == -1) {
return -1;
}
len[4] = 0;
n = strtol(len, &e, 16);
- if(n == 0){
- if(chattygit)
+ if (n == 0) {
+ if (chattygit)
fprintf(stderr, "readpkt: 0000\n");
return 0;
}
- if(e != len + 4 || n <= 4)
+ if (e != len + 4 || n <= 4)
err(1, "invalid packet line length");
n -= 4;
- if(n >= nbuf)
+ if (n >= nbuf)
err(1, "buffer too small");
- if((r = readn(fd, buf, n)) != n)
+ if ((r = readn(fd, buf, n)) != n)
return -1;
buf[n] = 0;
- if(chattygit)
+ if (chattygit)
fprintf(stderr, "readpkt: %s:\t%.*s\n", len, nbuf, buf);
return n;
}
if (snprintf(len, sizeof(len), "%04x", nbuf + 4) >= sizeof(len))
return -1;
- if(write(fd, len, 4) != 4)
+ if (write(fd, len, 4) != 4)
return -1;
- if(write(fd, buf, nbuf) != nbuf)
+ if (write(fd, buf, nbuf) != nbuf)
return -1;
- if(chattygit){
+ if (chattygit) {
fprintf(stderr, "writepkt: %s:\t", len);
fwrite(buf, 1, nbuf, stderr);
- for(i = 0; i < nbuf; i++){
- if(isprint(buf[i]))
+ for (i = 0; i < nbuf; i++) {
+ if (isprint(buf[i]))
fputc(buf[i], stderr);
}
}
char buf[128], *s;
int r, f;
- if(!got_parse_sha1_digest(id->sha1, ref))
+ if (!got_parse_sha1_digest(id->sha1, ref))
return 0;
/* Slightly special handling: translate remote refs to local ones. */
if (strcmp(ref, "HEAD") == 0) {
- if(snprintf(buf, sizeof(buf), ".git/HEAD") >= sizeof(buf))
+ if (snprintf(buf, sizeof(buf), ".git/HEAD") >= sizeof(buf))
return -1;
- } else if(strstr(ref, "refs/heads") == ref) {
+ } else if (strstr(ref, "refs/heads") == ref) {
ref += strlen("refs/heads");
- if(snprintf(buf, sizeof(buf),
+ if (snprintf(buf, sizeof(buf),
".git/refs/remotes/%s/%s", upstream, ref) >= sizeof(buf))
return -1;
- } else if(strstr(ref, "refs/tags") == ref) {
+ } else if (strstr(ref, "refs/tags") == ref) {
ref += strlen("refs/tags");
- if(snprintf(buf, sizeof(buf),
+ if (snprintf(buf, sizeof(buf),
".git/refs/tags/%s/%s", upstream, ref) >= sizeof(buf))
return -1;
} else {
r = -1;
s = buf;
- if((f = open(s, O_RDONLY)) == -1)
+ if ((f = open(s, O_RDONLY)) == -1)
goto err;
- if(readn(f, buf, sizeof(buf)) < 40)
+ if (readn(f, buf, sizeof(buf)) < 40)
goto err;
- if(!got_parse_sha1_digest(id->sha1, buf))
+ if (!got_parse_sha1_digest(id->sha1, buf))
goto err;
err:
close(f);
- if(r == -1 && strstr(buf, "ref:") == buf)
+ if (r == -1 && strstr(buf, "ref:") == buf)
return got_resolve_remote_ref(id, buf + strlen("ref:"));
return r;
}
uint8_t buf[32*1024];
ssize_t n, r, nr;
- if(sz < 28)
+ if (sz < 28)
return -1;
n = 0;
SHA1Init(&ctx);
- while(n < sz - 20){
+ while (n < sz - 20) {
nr = sizeof(buf);
- if(sz - n - 20 < sizeof(buf))
+ if (sz - n - 20 < sizeof(buf))
nr = sz - n - 20;
r = readn(fd, buf, nr);
- if(r != nr)
+ if (r != nr)
return -1;
SHA1Update(&ctx, buf, nr);
n += r;
}
SHA1Final(hcomp, &ctx);
- if(readn(fd, hexpect, sizeof(hexpect)) != sizeof(hexpect))
+ if (readn(fd, hexpect, sizeof(hexpect)) != sizeof(hexpect))
errx(1, "truncated packfile");
- if(memcmp(hcomp, hexpect, SHA1_DIGEST_LENGTH) != 0){
+ if (memcmp(hcomp, hexpect, SHA1_DIGEST_LENGTH) != 0) {
got_sha1_digest_to_str(hcomp, s1, sizeof(s1));
got_sha1_digest_to_str(hexpect, s2, sizeof(s2));
printf("hash mismatch %s != %s\n", s1, s2);
char s[128];
char *p;
- if(snprintf(s, sizeof(s), "%s", path) >= sizeof(s))
+ if (snprintf(s, sizeof(s), "%s", path) >= sizeof(s))
return -1;
- for(p=strchr(s+1, '/'); p; p=strchr(p+1, '/')){
+ for (p = strchr(s + 1, '/'); p; p = strchr(p + 1, '/')) {
*p = 0;
if (mkdir(s, 0755) == -1)
- if(errno != EEXIST)
+ if (errno != EEXIST)
return -1;
*p = '/';
}
{
char name[128];
- if(strstr(pat, "refs/heads") == pat) {
+ if (strstr(pat, "refs/heads") == pat) {
if (snprintf(name, sizeof(name), "%s", pat) >= sizeof(name))
return -1;
- } else if(strstr(pat, "heads")) {
- if (snprintf(name, sizeof(name), "refs/%s", pat) >= sizeof(name))
+ } else if (strstr(pat, "heads")) {
+ if (snprintf(name, sizeof(name), "refs/%s", pat)
+ >= sizeof(name))
return -1;
} else {
- if (snprintf(name, sizeof(name), "refs/heads/%s", pat) >= sizeof(name))
+ if (snprintf(name, sizeof(name), "refs/heads/%s", pat)
+ >= sizeof(name))
return -1;
}
return strcmp(br, name) == 0;
fprintf(stderr, "starting fetch\n");
while (1) {
n = readpkt(fd, buf, sizeof(buf));
- if (n == -1){
+ if (n == -1) {
err = got_error_from_errno("readpkt");
goto done;
}
continue;
if (fetchbranch && !got_match_branch(sp[1], fetchbranch))
continue;
- if (refsz == nref + 1){
+ if (refsz == nref + 1) {
refsz *= 2;
have = realloc(have, refsz * sizeof(have[0]));
if (have == NULL) {
}
req = 0;
- for (i = 0; i < nref; i++){
+ for (i = 0; i < nref; i++) {
if (got_object_id_cmp(&have[i], &want[i]) == 0)
continue;
if (got_has_object(&want[i]))
req = 1;
}
flushpkt(fd);
- for (i = 0; i < nref; i++){
+ for (i = 0; i < nref; i++) {
if (got_object_id_cmp(&have[i], &zhash) == 0)
continue;
got_sha1_digest_to_str(want[i].sha1, hashstr, sizeof(hashstr));
goto done;
}
}
- if (!req){
+ if (!req) {
fprintf(stderr, "up to date\n");
flushpkt(fd);
}
struct imsgbuf ibuf;
struct imsg imsg;
- if(getenv("GOT_DEBUG") != NULL){
+ if (getenv("GOT_DEBUG") != NULL) {
fprintf(stderr, "fetch-pack being chatty!\n");
chattygit = 1;
}
imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
- if((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
+ if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
if (err->code == GOT_ERR_PRIVSEP_PIPE)
err = NULL;
goto done;
}
fetchfd = imsg.fd;
- if((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
+ if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
if (err->code == GOT_ERR_PRIVSEP_PIPE)
err = NULL;
goto done;
got_privsep_send_error(&ibuf, err);
else
err = got_privsep_send_fetch_done(&ibuf, packid);
- if(err != NULL) {
+ if (err != NULL) {
fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
got_privsep_send_error(&ibuf, err);
}