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