ref: 9ec38f3162c5c7f1a7fe136bab160e76df13a7ba
parent: f5805c3552dd00a6018f8440c1a4c8aa6755fd03
author: Ori Bernstein <[email protected]>
date: Thu Oct 17 10:37:20 EDT 2019
Skip packing data if the other side has the commit.
--- a/fetch.c
+++ b/fetch.c
@@ -160,6 +160,7 @@
getfields(buf, sp, nelem(sp), 1, " \t\n\r");
if(strstr(sp[1], "^{}"))
continue;
+ print("sp[1]: %s\n", sp[1]);
if(fetchbranch && !branchmatch(sp[1], fetchbranch))
continue;
if(refsz == nref + 1){
--- a/pull
+++ b/pull
@@ -11,6 +11,7 @@
url=$3
dir=$4
+ echo git/fetch -b $branch -u $upstream $url
fetch=`"{git/fetch -b $branch -u $upstream $url |[2] tr '\x0d' '\x0a'}
st=$status
if(! ~ $st ''){
@@ -39,11 +40,6 @@
exit usage
}
-branch=`{awk '$1=="branch"{print $2}' < /mnt/git/ctl}
-remote=()
-incoming=()
-checkout='true'
-upstream=origin
if(! cd `{git/conf -r}){
echo 'not in git repository' >[1=2]
@@ -50,6 +46,11 @@
exit notgit
}
git/fs
+branch=refs/`{git/branch}
+remote=()
+incoming=()
+checkout='true'
+upstream=origin
while(~ $1 -*){
switch($1){
--- a/send.c
+++ b/send.c
@@ -287,7 +287,7 @@
int
sendpack(int fd)
{
- int i, n, r, nupd, nsp, updating;
+ int i, n, r, nupd, nsp, sendpack;
char buf[Pktmax], *sp[3];
Update *upd, *u;
Object *a, *b;
@@ -313,7 +313,7 @@
}
r = 0;
- updating = 0;
+ sendpack = 0;
for(i = 0; i < nupd; i++){
u = &upd[i];
a = readobject(u->theirs);
@@ -321,7 +321,7 @@
if(!force && !hasheq(&u->theirs, &Zhash) && (a == nil || ancestor(a, b) != a)){
fprint(2, "remote has diverged\n");
werrstr("force needed");
- updating=0;
+ sendpack=0;
r = -1;
break;
}
@@ -352,10 +352,15 @@
}
if(writepkt(fd, buf, n) == -1)
sysfatal("unable to send update pkt");
- updating = 1;
+ /*
+ * If we're rolling back with a force push, the other side already
+ * has our changes. There's no need to send a pack if that's the case.
+ */
+ if(!ancestor(b, a))
+ sendpack = 1;
}
flushpkt(fd);
- if(updating){
+ if(sendpack){
if(writepack(fd, upd, nupd) == -1)
return -1;