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

Re: [PATCH 2/4] rev-parse: make --git-dir return /.git instead of //.git

From
Johannes Sixt <j6t@kdbg.org>
Date
Feb 9, 2010, 19:18 UTC
Message-ID
<201002092018.55951.j6t@kdbg.org>
In-Reply-To
<1265734950-15145-2-git-send-email-pclouds@gmail.com>
On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:
Show 6 quoted lines
> @@ -647,7 +647,7 @@ int cmd_rev_parse(int argc, const char **argv, const
> char *prefix) }
>  				if (!getcwd(cwd, PATH_MAX))
>  					die_errno("unable to get current working directory");
> -				printf("%s/.git\n", cwd);
> +				printf("%s%s.git\n", cwd, *cwd == '/' && cwd[1] == '\0' ? "" : "/");

On Windows, when you are in the root of a drive, then cwd is "C:/", i.e. there is a trailing slash just as in the Unix root directory. But you do not take care of this situation. That is, you would print "C://".

How about:
static inline int is_root_path(const char *path)
{
	if (has_dos_drive_prefix(path))
		path += 2;
	while (is_dir_sep(*path))
		path++;
	return !*path;
}
and use it though-out your series?

(Simplify the loop to 'return is_dir_sep(*path) && !path[1];' if you can assume that paths are nomalized.)

-- Hannes
Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 3 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.