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

[PATCH] Fix the remote note the fetch-tool prints after storing a fetched reference

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jun 6, 2007, 15:52 UTC
Message-ID
<81b0412b0706060852y4ab6b794m5fed0484c63159e4@mail.gmail.com>
In-Reply-To
<81b0412b0706060045k4098eb05tc596214f8d9673bf@mail.gmail.com>

Otherwise ".git" is removed from every remote path which has it, including "/some/path/somename.git".

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

Fixed truncation of "/.git/" (with a trailing slash). The old code broke t5515, because it has left "../.git/" unchanged, but should have removed ".git/".

 builtin-fetch--tool.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
From c767dcc2000c72909013b9e97b18403686b44498 Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa@limbo.localdomain>
Date: Wed, 6 Jun 2007 00:16:14 +0200
Subject: [PATCH] Fix the remote note the fetch-tool prints after storing a fetched reference
Otherwise ".git" is removed from every remote name which has it:
  $ git fetch -v
    * refs/heads/origin: same as branch 'master' of /home/user/linux
      commit: 5ecd310
  $ ls /home/user/linux
  ls: /home/user/linux: No such file or directory
  $ ls /home/user/linux.git
  HEAD  objects  packed-refs  ...
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 builtin-fetch--tool.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index ed4d5de..ec4a8c3 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -140,7 +140,7 @@ static int append_fetch_head(FILE *fp,
 			     int verbose, int force)
 {
 	struct commit *commit;
-	int remote_len, i, note_len;
+	int remote_len, note_len;
 	unsigned char sha1[20];
 	char note[1024];
 	const char *what, *kind;
@@ -173,11 +173,20 @@ static int append_fetch_head(FILE *fp,
 	}
 
 	remote_len = strlen(remote);
-	for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
-		;
-	remote_len = i + 1;
-	if (4 < i && !strncmp(".git", remote + i - 3, 4))
-		remote_len = i - 3;
+	if (remote_len > 5) {
+		static const char ending[] = "/.git";
+		const char *pe = ending + 4;
+		const char *pr = remote + remote_len - 1;
+		/* ignore trailing slashes */
+		while (pr > remote && *pr == '/')
+			--pr;
+		for (; pr > remote && pe > ending; --pr, --pe)
+			if (*pr != *pe)
+				break;
+		if (pe == ending)
+			/* "+ 1" to leave the / before .git */
+			remote_len = pr - remote + 1;
+	}
 
 	note_len = 0;
 	if (*what) {
-- 
1.5.2.1.868.gb85c1
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 9 in “Fix the remote note the fetch-tool prints after storing a fetched reference”
  1. Fix the remote note the fetch-tool prints after storing a fetched referenceAlex Riesen, Jun 6, 2007
  2. Junio C HamanoJun 6, 2007
  3. Alex RiesenJun 6, 2007
  4. J Junio C HamanoJun 6, 2007
  5. Alex RiesenJun 6, 2007
  6. Junio C HamanoJun 6, 2007
  7. Fix the remote note the fetch-tool prints after storing a fetched referenceAlex Riesen, Jun 6, 2007
  8. Junio C HamanoJun 6, 2007
  9. Alex RiesenJun 6, 2007

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.