| @@ -12,7 +12,8 @@ enum { · 11 unmodified lines |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | 14 | Object *indexed; |
| 15 | | −char *clonebranch; |
| 15 | +char *fetchbranch; |
| 16 | +char *upstream = "origin"; |
| 16 | 17 | char *packtmp = ".git/objects/pack/fetch.tmp"; |
| 17 | 18 | |
| 18 | 19 | static int |
| @@ -171,10 +172,10 @@ resolveremote(Hash *h, char *ref) · 152 unmodified lines |
| 171 | 172 | snprint(buf, sizeof(buf), ".git/HEAD"); |
| 172 | 173 | }else if(strstr(ref, "refs/heads") == ref){ |
| 173 | 174 | ref += strlen("refs/heads"); |
| 174 | | − snprint(buf, sizeof(buf), ".git/refs/remotes/%s/%s", clonebranch, ref); |
| 175 | + snprint(buf, sizeof(buf), ".git/refs/remotes/%s/%s", upstream, ref); |
| 175 | 176 | }else if(strstr(ref, "refs/tags") == ref){ |
| 176 | 177 | ref += strlen("refs/tags"); |
| 177 | | − snprint(buf, sizeof(buf), ".git/refs/tags/%s/%s", clonebranch, ref); |
| 178 | + snprint(buf, sizeof(buf), ".git/refs/tags/%s/%s", upstream, ref); |
| 178 | 179 | }else{ |
| 179 | 180 | return -1; |
| 180 | 181 | } |
| @@ -270,6 +271,20 @@ mkoutpath(char *path) · 89 unmodified lines |
| 270 | 271 | return 0; |
| 271 | 272 | } |
| 272 | 273 | |
| 274 | +int |
| 275 | +branchmatch(char *br, char *pat) |
| 276 | +{ |
| 277 | + char name[128]; |
| 278 | + |
| 279 | + if(strstr(pat, "refs/heads") == pat) |
| 280 | + snprint(name, sizeof(name), "%s", pat); |
| 281 | + else if(strstr(pat, "heads")) |
| 282 | + snprint(name, sizeof(name), "refs/%s", pat); |
| 283 | + else |
| 284 | + snprint(name, sizeof(name), "refs/heads/%s", pat); |
| 285 | + return strcmp(br, name) == 0; |
| 286 | +} |
| 287 | + |
| 273 | 288 | int |
| 274 | 289 | fetchpack(int fd, int pfd, char *packtmp) |
| 275 | 290 | { |
| @@ -296,11 +311,13 @@ fetchpack(int fd, int pfd, char *packtmp) · 20 unmodified lines |
| 296 | 311 | getfields(buf, sp, nelem(sp), 1, " \t\n\r"); |
| 297 | 312 | if(strstr(sp[1], "^{}")) |
| 298 | 313 | continue; |
| 314 | + if(fetchbranch && !branchmatch(sp[1], fetchbranch)) |
| 315 | + continue; |
| 299 | 316 | if(refsz == nref + 1){ |
| 300 | 317 | refsz *= 2; |
| 301 | 318 | have = erealloc(have, refsz * sizeof(have[0])); |
| 302 | 319 | want = erealloc(want, refsz * sizeof(want[0])); |
| 303 | | − } |
| 320 | + } |
| 304 | 321 | if(hparse(&want[nref], sp[0]) == -1) |
| 305 | 322 | sysfatal("invalid hash %s", sp[0]); |
| 306 | 323 | if (resolveremote(&have[nref], sp[1]) == -1) |
| @@ -331,10 +348,12 @@ fetchpack(int fd, int pfd, char *packtmp) · 24 unmodified lines |
| 331 | 348 | fprint(2, "up to date\n"); |
| 332 | 349 | flushpkt(fd); |
| 333 | 350 | } |
| 334 | | − |
| 335 | 351 | n = snprint(buf, sizeof(buf), "done\n"); |
| 336 | 352 | if(writepkt(fd, buf, n) == -1) |
| 337 | 353 | sysfatal("lost connection write"); |
| 354 | + if(!req) |
| 355 | + return 0; |
| 356 | + |
| 338 | 357 | if((n = readpkt(fd, buf, sizeof(buf))) == -1) |
| 339 | 358 | sysfatal("lost connection read"); |
| 340 | 359 | buf[n] = 0; |
| @@ -381,7 +400,8 @@ main(int argc, char **argv) · 40 unmodified lines |
| 381 | 400 | int fd, pfd; |
| 382 | 401 | |
| 383 | 402 | ARGBEGIN{ |
| 384 | | − case 'b': clonebranch=EARGF(usage()); break; |
| 403 | + case 'b': fetchbranch=EARGF(usage()); break; |
| 404 | + case 'u': upstream=EARGF(usage()); break; |
| 385 | 405 | default: usage(); break; |
| 386 | 406 | }ARGEND; |
| 387 | 407 | |