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

[PATCH 1/4] make_absolute_path(): Do not append redundant slash

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 9, 2010, 17:02 UTC
Message-ID
<1265734950-15145-1-git-send-email-pclouds@gmail.com>

make_absolute_path("foo") at root returns "//foo". This patch makes it return "/foo" correctly.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 .. so that "git init" will show "initialized empty Git in /.git"
 abspath.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/abspath.c b/abspath.c
index b88122c..e72aede 100644
--- a/abspath.c
+++ b/abspath.c
@@ -54,8 +54,9 @@ const char *make_absolute_path(const char *path)
 			if (len + strlen(last_elem) + 2 > PATH_MAX)
 				die ("Too long path name: '%s/%s'",
 						buf, last_elem);
-			buf[len] = '/';
-			strcpy(buf + len + 1, last_elem);
+			if (*buf != '/' || buf[1] != '\0')
+				buf[len++] = '/';
+			strcpy(buf + len, last_elem);
 			free(last_elem);
 			last_elem = NULL;
 		}
-- 
1.7.0.rc2.182.g3adef
Next: Nguyễn Thái Ngọc Duy
Message 1 of 12 in “make_absolute_path(): Do not append redundant slash”
  1. 1/4 make_absolute_path(): Do not append redundant slashNguyễn Thái Ngọc Duy, Feb 9, 2010
  2. 2/4 rev-parse: make --git-dir return /.git instead of //.gitNguyễn Thái Ngọc Duy, Feb 9, 2010
  3. Johannes SixtFeb 9, 2010
  4. Nguyen Thai Ngoc DuyFeb 11, 2010
  5. 3/4 Support working directory located at rootNguyễn Thái Ngọc Duy, Feb 9, 2010
  6. Johannes SixtFeb 9, 2010
  7. Nguyen Thai Ngoc DuyFeb 11, 2010
  8. 4/4 Add test for using Git at root of file systemNguyễn Thái Ngọc Duy, Feb 9, 2010
  9. João Carlos Mendes LuísFeb 10, 2010
  10. Nguyen Thai Ngoc DuyFeb 11, 2010
  11. Johannes SixtFeb 9, 2010
  12. Nguyen Thai Ngoc DuyFeb 11, 2010

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.