]> git.ipfire.org Git - thirdparty/git.git/blobdiff - path.c
The tenth batch
[thirdparty/git.git] / path.c
diff --git a/path.c b/path.c
index 9a62b6faaee935606f3a97c2bfb6dcd8c274de12..adfb3d3eb709b3028eb4a41ef3306d34279cc01c 100644 (file)
--- a/path.c
+++ b/path.c
@@ -5,7 +5,6 @@
 #include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
-#include "hex.h"
 #include "repository.h"
 #include "strbuf.h"
 #include "string-list.h"
@@ -647,58 +646,6 @@ void strbuf_git_common_path(struct strbuf *sb,
        va_end(args);
 }
 
-int validate_headref(const char *path)
-{
-       struct stat st;
-       char buffer[256];
-       const char *refname;
-       struct object_id oid;
-       int fd;
-       ssize_t len;
-
-       if (lstat(path, &st) < 0)
-               return -1;
-
-       /* Make sure it is a "refs/.." symlink */
-       if (S_ISLNK(st.st_mode)) {
-               len = readlink(path, buffer, sizeof(buffer)-1);
-               if (len >= 5 && !memcmp("refs/", buffer, 5))
-                       return 0;
-               return -1;
-       }
-
-       /*
-        * Anything else, just open it and try to see if it is a symbolic ref.
-        */
-       fd = open(path, O_RDONLY);
-       if (fd < 0)
-               return -1;
-       len = read_in_full(fd, buffer, sizeof(buffer)-1);
-       close(fd);
-
-       if (len < 0)
-               return -1;
-       buffer[len] = '\0';
-
-       /*
-        * Is it a symbolic ref?
-        */
-       if (skip_prefix(buffer, "ref:", &refname)) {
-               while (isspace(*refname))
-                       refname++;
-               if (starts_with(refname, "refs/"))
-                       return 0;
-       }
-
-       /*
-        * Is this a detached HEAD?
-        */
-       if (!get_oid_hex(buffer, &oid))
-               return 0;
-
-       return -1;
-}
-
 static struct passwd *getpw_str(const char *username, size_t len)
 {
        struct passwd *pw;
@@ -829,6 +776,7 @@ const char *enter_repo(const char *path, int strict)
                if (!suffix[i])
                        return NULL;
                gitfile = read_gitfile(used_path.buf);
+               die_upon_dubious_ownership(gitfile, NULL, used_path.buf);
                if (gitfile) {
                        strbuf_reset(&used_path);
                        strbuf_addstr(&used_path, gitfile);
@@ -839,6 +787,7 @@ const char *enter_repo(const char *path, int strict)
        }
        else {
                const char *gitfile = read_gitfile(path);
+               die_upon_dubious_ownership(gitfile, NULL, path);
                if (gitfile)
                        path = gitfile;
                if (chdir(path))
@@ -854,7 +803,7 @@ const char *enter_repo(const char *path, int strict)
        return NULL;
 }
 
-static int calc_shared_perm(int mode)
+int calc_shared_perm(int mode)
 {
        int tweak;