9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: Re: [9front] git/pull: fetch all branches (please test)
Date: Mon, 11 Apr 2022 17:32:53 -0400	[thread overview]
Message-ID: <6E68ADE1468D00715CFB8A660CA41558@eigenstate.org> (raw)
In-Reply-To: <6E9FAB4543B7BD25248B817B51F054F6@eigenstate.org>

Quoth ori@eigenstate.org:
> Here's the work in progress

And here's an updated work in progress that works around
the bug more directly:

diff 1d9d4ffef89e883949261ec9c56c57e0344726d7 uncommitted
--- a/sys/src/cmd/git/fetch.c
+++ b/sys/src/cmd/git/fetch.c
@@ -186,6 +186,7 @@
 	int nref, refsz, first;
 	int i, n, req, pfd;
 	vlong packsz;
+	Objset hadobj;
 	Object *o;
 
 	nref = 0;
@@ -246,13 +247,19 @@
 		req = 1;
 	}
 	flushpkt(c);
+	osinit(&hadobj);
 	for(i = 0; i < nref; i++){
-		if(hasheq(&have[i], &Zhash))
+		if(hasheq(&have[i], &Zhash) || oshas(&hadobj, have[i]))
 			continue;
+		if((o = readobject(have[i])) == nil)
+			sysfatal("missing object we should have: %H", have[i]);
+		osadd(&hadobj, o);
+		unref(o);	
 		n = snprint(buf, sizeof(buf), "have %H\n", have[i]);
 		if(writepkt(c, buf, n + 1) == -1)
 			sysfatal("could not send have for %H", have[i]);
 	}
+	osclear(&hadobj);
 	if(!req)
 		flushpkt(c);
 
@@ -260,7 +267,7 @@
 	if(writepkt(c, buf, n) == -1)
 		sysfatal("write: %r");
 	if(!req)
-		return 0;
+		goto showrefs;
 	if(readphase(c) == -1)
 		sysfatal("read: %r");
 	if((n = readpkt(c, buf, sizeof(buf))) == -1)
@@ -277,7 +284,24 @@
 		sysfatal("could not create %s: %r", packtmp);
 
 	fprint(2, "fetching...\n");
+	/*
+	 * Work around torvalds git bug: we get duplicate have lines
+	 * somtimes, even though the protocol is supposed to start the
+	 * pack file immediately.
+	 *
+	 * Skip ahead until we read 'PACK' off the wire
+	 */
+	if(readn(c->rfd, buf, 4) != 4)
+		sysfatal("fetch packfile: short read");
+	while(1){
+		if(strncmp(buf, "PACK", 4) == 0)
+			break;
+		memmove(buf, buf + 1, 3);
+		if(read(c->rfd, buf+3, 1) != 1)
+			sysfatal("fetch packfile: could not scan for pack start");
+	}
 	packsz = 0;
+	write(pfd, "PACK", 4);
 	while(1){
 		n = read(c->rfd, buf, sizeof buf);
 		if(n == 0)
--- a/sys/src/cmd/git/pull
+++ b/sys/src/cmd/git/pull
@@ -7,13 +7,10 @@
 	upstream=$2
 	url=$3
 	dir=$4
-	bflag=()
 	dflag=()
-	if(! ~ $#branch 0)
-		bflag=(-b $branch)
 	if(! ~ $#debug 0)
 		dflag='-d'
-	{git/fetch $dflag $bflag -u $upstream $url >[2=3] || die $status} | awk '
+	{git/fetch $dflag -u $upstream $url >[2=3] || die $status} | awk '
 	/^remote/{
 		if($2=="HEAD")
 			next


  reply	other threads:[~2022-04-11 21:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11  3:19 ori
2022-04-11 21:32 ` ori [this message]
2022-04-12  2:55   ` ori
2022-04-19 19:31     ` Michael Forney
2022-04-20  3:42       ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6E68ADE1468D00715CFB8A660CA41558@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    --subject='Re: [9front] git/pull: fetch all branches (please test)' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).