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

Re: [PATCH 1/5] Add platform-independent .git "symlink"

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 18, 2008, 05:43 UTC
Message-ID
<7v7ih2u8e1.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1203286456-26033-2-git-send-email-hjemli@gmail.com>
Lars Hjemli <hjemli@gmail.com> writes:
> This patch allows .git to be a regular textfile containing the path of
> the real git directory (formatted like "gitdir: <path>\n"), which is
> useful on platforms lacking support for real symlinks.

Hmmmm. I have suspected all along that these "platforms lacking support for real symlinks" are the ones whose native line termination convention is CRLF. How do you envision this file is initialized? By users editing the file by hand? Or some git specific tool? If the former, it might make sense to define the format as "a single line, terminated with platform line terminator" and open and read it in text mode. If the latter, we do not have to care, and "terminated with LF" is good enough.

I think a sane simplification is to allow the file to have any number of optional \r or \n at the end. We may care about allowing arbitrary and possibly crazy filenames in the tracked contents, but we can say "Sorry, you cannot create a directory 'ab\nc\r' and use it as the .git directory substitute."

Show 14 quoted lines
> +const char *read_gitfile_gently(const char *path)
> +{
> +	static char buf[PATH_MAX + 9];  /* "gitdir: " + "\n" */
> +	struct stat st;
> +	int fd;
> +	size_t len;
> +
> +	if (stat(path, &st))
> +		return NULL;
> +	if (!S_ISREG(st.st_mode) || st.st_size >= sizeof(buf))
> +		return NULL;
> +	fd = open(path, O_RDONLY);
> +	if (fd < 0)
> +		return NULL;
Up to this point it is fine "gently" semantics.
Show 9 quoted lines
> +	len = read_in_full(fd, buf, sizeof(buf));
> +	close(fd);
> +	if (len != st.st_size)
> +		return NULL;
> +	if (!len || buf[len - 1] != '\n')
> +		return NULL;
> +	buf[len - 1] = '\0';
> +	if (prefixcmp(buf, "gitdir: "))
> +		return NULL;

But I am not sure about this part. We found what claims to be the ".git" fake symlink but it is ill-formed. Don't we want to diagnose the possible breakage for the user?

> +/*
> +	if (!is_git_directory(buf + 8))
> +		return NULL;
> +*/
Likewise.
Previous: Lars HjemliNext: Lars Hjemli
Message 12 of 17 in “Intoducing the .git file (again)”
  1. Lars HjemliFeb 17, 2008
  2. 1/5 Add platform-independent .git "symlink"Lars Hjemli, Feb 17, 2008
  3. 2/5 Fix setup of $GIT_DIR in git-sh-setup.shLars Hjemli, Feb 17, 2008
  4. 3/5 Teach resolve_gitlink_ref() about the .git fileLars Hjemli, Feb 17, 2008
  5. 4/5 git-submodule: prepare for the .git-fileLars Hjemli, Feb 17, 2008
  6. 5/5 Teach GIT-VERSION-GEN about the .git fileLars Hjemli, Feb 17, 2008
  7. Junio C HamanoFeb 18, 2008
  8. Lars HjemliFeb 18, 2008
  9. Johannes SchindelinFeb 17, 2008
  10. Lars HjemliFeb 17, 2008
  11. 1/5 Add platform-independent .git "symlink"Lars Hjemli, Feb 17, 2008
  12. Junio C HamanoFeb 18, 2008
  13. Lars HjemliFeb 18, 2008
  14. Johannes SchindelinFeb 18, 2008
  15. Johannes SchindelinFeb 17, 2008
  16. Lars HjemliFeb 17, 2008
  17. Johannes SchindelinFeb 17, 2008

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.