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

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 2, 2008, 15:56 UTC
Message-ID
<alpine.LSU.1.00.0802021550130.7372@racer.site>
In-Reply-To
<1201948579-11807-1-git-send-email-hjemli@gmail.com>
Hi,
On Sat, 2 Feb 2008, Lars Hjemli wrote:
> 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.
Wow, that looks easier than I thought...
> +static const char *read_gitfile_gently(const char *path)
> +{
> +	static char buf[PATH_MAX + 10];  /* "GITDIR: " + "\n" + "\0" */

Why say "GITDIR:"? Do you want to be able to set other things there, too, like GITWORKDIR?

Show 7 quoted lines
> +	struct stat st;
> +	FILE *f;
> +	size_t len;
> +
> +	if (stat(path, &st))
> +		return NULL;
> +	if (!S_ISREG(st.st_mode) || st.st_size > PATH_MAX + 9)

Why make it complicated? You could just test for st.st_size >= sizeof(buf).

Show 8 quoted lines
> +		return NULL;
> +	f = fopen(path, "r");
> +	if (!f)
> +		return NULL;
> +	len = fread(buf, 1, st.st_size, f);
> +	fclose(f);
> +	if (len != st.st_size)
> +		return NULL;
Should this not rather use read_in_full()?
Show 7 quoted lines
> +	if (len < 10 || buf[len - 1] != '\n' || strncmp(buf, "GITDIR: ", 8))
> +		return NULL;
> +	buf[len - 1] = '\0';
> +	if (!is_git_directory(buf + 8))
> +		return NULL;
> +	return buf + 8;
> +}
Should this not make the git directory absolute, just in case?

Thanks, Dscho

Previous: Lars HjemliNext: Lars Hjemli
Message 3 of 29 in “Add platform-independent .git "symlink"”
  1. Add platform-independent .git "symlink"Lars Hjemli, Feb 2, 2008
  2. Add tests for .git fileLars Hjemli, Feb 2, 2008
  3. Johannes SchindelinFeb 2, 2008
  4. Lars HjemliFeb 2, 2008
  5. Add platform-independent .git "symlink"Lars Hjemli, Feb 2, 2008
  6. Johannes SchindelinFeb 2, 2008
  7. Johannes SchindelinFeb 2, 2008
  8. Shawn O. PearceFeb 4, 2008
  9. Junio C HamanoFeb 4, 2008
  10. Johannes SchindelinFeb 4, 2008
  11. Brandon CaseyFeb 4, 2008
  12. Johannes SchindelinFeb 4, 2008
  13. Brandon CaseyFeb 4, 2008
  14. Johannes SchindelinFeb 4, 2008
  15. Brandon CaseyFeb 4, 2008
  16. Brandon CaseyFeb 4, 2008
  17. Johannes SchindelinFeb 5, 2008
  18. Johannes SchindelinFeb 5, 2008
  19. Brandon CaseyFeb 5, 2008
  20. Johannes SchindelinFeb 5, 2008
  21. Lars HjemliFeb 2, 2008
  22. Johannes SchindelinFeb 3, 2008
  23. Junio C HamanoFeb 4, 2008
  24. Johannes SchindelinFeb 4, 2008
  25. Shawn O. PearceFeb 4, 2008
  26. Junio C HamanoFeb 4, 2008
  27. Shawn O. PearceFeb 4, 2008
  28. Lars HjemliFeb 4, 2008
  29. Johannes SchindelinFeb 4, 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.