X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=path.c;h=c4ce96236ae043b4d997536174936abb6ac40207;hb=c1c10a3f272ec0908e63bc105a5ffe94c1279fba;hp=bb5ee7bf99780b6c4069dd9833994b24f1577e82;hpb=93d26e4cb9cec2eb8abb4f37e6dda2c86fcceeac;p=git.git diff --git a/path.c b/path.c index bb5ee7bf9..c4ce96236 100644 --- a/path.c +++ b/path.c @@ -90,10 +90,11 @@ int git_mkstemp(char *path, size_t len, const char *template) } -int validate_symref(const char *path) +int validate_headref(const char *path) { struct stat st; char *buf, buffer[256]; + unsigned char sha1[20]; int len, fd; if (lstat(path, &st) < 0) @@ -119,14 +120,23 @@ int validate_symref(const char *path) /* * Is it a symbolic ref? */ - if (len < 4 || memcmp("ref:", buffer, 4)) + if (len < 4) return -1; - buf = buffer + 4; - len -= 4; - while (len && isspace(*buf)) - buf++, len--; - if (len >= 5 && !memcmp("refs/", buf, 5)) + if (!memcmp("ref:", buffer, 4)) { + buf = buffer + 4; + len -= 4; + while (len && isspace(*buf)) + buf++, len--; + if (len >= 5 && !memcmp("refs/", buf, 5)) + return 0; + } + + /* + * Is this a detached HEAD? + */ + if (!get_sha1_hex(buffer, sha1)) return 0; + return -1; } @@ -241,8 +251,8 @@ char *enter_repo(char *path, int strict) return NULL; if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 && - validate_symref("HEAD") == 0) { - putenv("GIT_DIR=."); + validate_headref("HEAD") == 0) { + setenv(GIT_DIR_ENVIRONMENT, ".", 1); check_repository_format(); return path; }