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
1212 };
1313
1414 Object *indexed;
15−char *clonebranch;
15+char *fetchbranch;
16+char *upstream = "origin";
1617 char *packtmp = ".git/objects/pack/fetch.tmp";
1718
1819 static int
@@ -171,10 +172,10 @@ resolveremote(Hash *h, char *ref) · 152 unmodified lines
171172 snprint(buf, sizeof(buf), ".git/HEAD");
172173 }else if(strstr(ref, "refs/heads") == ref){
173174 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);
175176 }else if(strstr(ref, "refs/tags") == ref){
176177 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);
178179 }else{
179180 return -1;
180181 }
@@ -270,6 +271,20 @@ mkoutpath(char *path) · 89 unmodified lines
270271 return 0;
271272 }
272273
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+
273288 int
274289 fetchpack(int fd, int pfd, char *packtmp)
275290 {
@@ -296,11 +311,13 @@ fetchpack(int fd, int pfd, char *packtmp) · 20 unmodified lines
296311 getfields(buf, sp, nelem(sp), 1, " \t\n\r");
297312 if(strstr(sp[1], "^{}"))
298313 continue;
314+ if(fetchbranch && !branchmatch(sp[1], fetchbranch))
315+ continue;
299316 if(refsz == nref + 1){
300317 refsz *= 2;
301318 have = erealloc(have, refsz * sizeof(have[0]));
302319 want = erealloc(want, refsz * sizeof(want[0]));
303− }
320+ }
304321 if(hparse(&want[nref], sp[0]) == -1)
305322 sysfatal("invalid hash %s", sp[0]);
306323 if (resolveremote(&have[nref], sp[1]) == -1)
@@ -331,10 +348,12 @@ fetchpack(int fd, int pfd, char *packtmp) · 24 unmodified lines
331348 fprint(2, "up to date\n");
332349 flushpkt(fd);
333350 }
334−
335351 n = snprint(buf, sizeof(buf), "done\n");
336352 if(writepkt(fd, buf, n) == -1)
337353 sysfatal("lost connection write");
354+ if(!req)
355+ return 0;
356+
338357 if((n = readpkt(fd, buf, sizeof(buf))) == -1)
339358 sysfatal("lost connection read");
340359 buf[n] = 0;
@@ -381,7 +400,8 @@ main(int argc, char **argv) · 40 unmodified lines
381400 int fd, pfd;
382401
383402 ARGBEGIN{
384− case 'b': clonebranch=EARGF(usage()); break;
403+ case 'b': fetchbranch=EARGF(usage()); break;
404+ case 'u': upstream=EARGF(usage()); break;
385405 default: usage(); break;
386406 }ARGEND;
387407
pull+6−5
@@ -8,11 +8,11 @@ nl=' · 7 unmodified lines
88 fn update{
99 update=$1
1010 branch=$2
11− url=$3
12− dir=$4
11+ upstream=$3
12+ url=$4
13+ dir=$5
1314
14− echo git/fetch -b $branch $url
15− {git/fetch -b $branch $url >[2=3] | awk -v 'update='^$update '
15+ {git/fetch -b $branch -u $upstream $url >[2=3] | awk -v 'update='^$update '
1616 function writeref(ref, hash)
1717 {
1818 outfile = ".git/"ref
@@ -50,6 +50,7 @@ while(~ $1 -*){ · 31 unmodified lines
5050 case -u;
5151 shift
5252 remote=$1
53+ upstream=SOMEONE
5354 case -b:
5455 shift
5556 branch=$1
@@ -80,7 +81,7 @@ if(! git/walk -q){ · 24 unmodified lines
8081 exit 'dirty'
8182 }
8283 oldfiles=`$nl{git/walk -cfT}
83−update $update $branch $remote $dir
84+update $update $branch $upstream $remote $dir
8485 if(! ~ $update 0){
8586 rm -f $oldfiles
8687 tree=/mnt/git/HEAD/tree