git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fetch-pack should not ask for a ref which is already there

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 29, 2005, 08:42 UTC
Message-ID
<Pine.LNX.4.63.0509291034450.20717@wgmdd8.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vll1gl4ms.fsf@assigned-by-dhcp.cox.net>
Hi,
On Thu, 29 Sep 2005, Junio C Hamano wrote:
Show 8 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > With this patch, instead of blindly asking for every remote ref, fetch-pack
> > first looks in the local repository if that ref is already there.
> 
> This patch breaks things.  git-fetch-pack is supposed to report
> the resulting SHA1 and refs on its standard output.  If you are
> up to date with this patch you would lose that.

Yeah, sorry. I did not test that one. Maybe an automated test for git-fetch-pack would be useful after all...

How about the following? (I avoided an ugly goto, but had to duplicate code :-( )

---
[PATCH] fetch-pack should not ask for a ref which is already there

With this patch, instead of blindly asking for every remote ref, fetch-pack first looks in the local repository if that ref is already there.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 fetch-pack.c |   36 ++++++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 10 deletions(-)
fbef982e4c5c4591b8d5517ef1694ab71e29c9e5
diff --git a/fetch-pack.c b/fetch-pack.c
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -16,20 +16,27 @@ static int find_common(int fd[2], unsign
 	int count = 0, flushes = 0, retval;
 	FILE *revs;
 
-	revs = popen("git-rev-list $(git-rev-parse --all)", "r");
-	if (!revs)
-		die("unable to run 'git-rev-list'");
-
 	while (refs) {
 		unsigned char *remote = refs->old_sha1;
-		if (verbose)
-			fprintf(stderr,
-				"want %s (%s)\n", sha1_to_hex(remote),
-				refs->name);
-		packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
+		if(!has_sha1_file(remote)) {
+			if (verbose)
+				fprintf(stderr,
+					"want %s (%s)\n", sha1_to_hex(remote),
+					refs->name);
+			packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
+			count++;
+		}
 		refs = refs->next;
 	}
 	packet_flush(fd[1]);
+
+	if(count==0)
+		return 1;
+
+	revs = popen("git-rev-list $(git-rev-parse --all)", "r");
+	if (!revs)
+		die("unable to run 'git-rev-list'");
+
 	flushes = 1;
 	retval = -1;
 	while (fgets(line, sizeof(line), revs) != NULL) {
@@ -86,7 +93,16 @@ static int fetch_pack(int fd[2], int nr_
 		packet_flush(fd[1]);
 		die("no matching remote head");
 	}
-	if (find_common(fd, sha1, ref) < 0)
+	status = find_common(fd, sha1, ref);
+	if(status > 0) {
+		while (ref) {
+			printf("%s %s\n",
+			       sha1_to_hex(ref->old_sha1), ref->name);
+			ref = ref->next;
+		}
+		return 0;
+	}
+	if(status < 0)
 		fprintf(stderr, "warning: no common commits\n");
 	pid = fork();
 	if (pid < 0)
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 10 in “fetch-pack should not ask for a ref which is already there”
  1. fetch-pack should not ask for a ref which is already thereJohannes Schindelin, Sep 28, 2005
  2. Junio C HamanoSep 29, 2005
  3. Johannes SchindelinSep 29, 2005
  4. Junio C HamanoSep 29, 2005
  5. Johannes SchindelinSep 29, 2005
  6. Linus TorvaldsSep 29, 2005
  7. Johannes SchindelinSep 29, 2005
  8. Johannes SchindelinSep 29, 2005
  9. Linus TorvaldsSep 29, 2005
  10. Johannes SchindelinSep 30, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.