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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

> +	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).

> +		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()?

> +	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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux