History

merge

Ori Bernstein committed 7 years ago

Commit f4fa7e82 parents e2c73c2 f88782e2 files · +32 −11Browse files

Unified · Split

2 files
  1. fetch.c +26 −6
  2. pull +6 −5
fetch.c+26−6
@@ -12,7 +12,8 @@ enum { · 11 unmodified lines
12};12};
13 13
14Object *indexed;14Object *indexed;
15char *clonebranch;15char *fetchbranch;
16char *upstream = "origin";
16char *packtmp = ".git/objects/pack/fetch.tmp";17char *packtmp = ".git/objects/pack/fetch.tmp";
17 18
18static int19static 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
274int
275branchmatch(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
273int288int
274fetchpack(int fd, int pfd, char *packtmp)289fetchpack(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
pull+6−5
@@ -8,11 +8,11 @@ nl=' · 7 unmodified lines
8fn update{8fn update{
9 update=$19 update=$1
10 branch=$210 branch=$2
11 url=$311 upstream=$3
12 dir=$412 url=$4
13 dir=$5
13 14
14 echo git/fetch -b $branch $url15 {git/fetch -b $branch -u $upstream $url >[2=3] | awk -v 'update='^$update '
15 {git/fetch -b $branch $url >[2=3] | awk -v 'update='^$update '
16 function writeref(ref, hash)16 function writeref(ref, hash)
17 {17 {
18 outfile = ".git/"ref18 outfile = ".git/"ref
@@ -50,6 +50,7 @@ while(~ $1 -*){ · 31 unmodified lines
50 case -u;50 case -u;
51 shift51 shift
52 remote=$152 remote=$1
53 upstream=SOMEONE
53 case -b:54 case -b:
54 shift55 shift
55 branch=$156 branch=$1
@@ -80,7 +81,7 @@ if(! git/walk -q){ · 24 unmodified lines
80 exit 'dirty'81 exit 'dirty'
81}82}
82oldfiles=`$nl{git/walk -cfT}83oldfiles=`$nl{git/walk -cfT}
83update $update $branch $remote $dir84update $update $branch $upstream $remote $dir
84if(! ~ $update 0){85if(! ~ $update 0){
85 rm -f $oldfiles86 rm -f $oldfiles
86 tree=/mnt/git/HEAD/tree87 tree=/mnt/git/HEAD/tree