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