Subject: [PATCH/POC 4/7] setup.c: add split-repo support to is_git_directory()

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Wed, 11 Dec 2013 21:15:30 +0700

Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
---
 setup.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/setup.c b/setup.c
index 84362a6..43f56fb 100644
--- a/setup.c
+++ b/setup.c
@@ -182,28 +182,31 @@ void verify_non_filename(const char *prefix, const char *arg)
  *    a proper "ref:", or a regular file HEAD that has a properly
  *    formatted sha1 object name.
  */
-int is_git_directory(const char *suspect)
+static int is_git_directory_super(const char *suspect, const char *super)
 {
 	char path[PATH_MAX];
 	size_t len = strlen(suspect);
+	size_t super_len = strlen(super);
 
-	if (PATH_MAX <= len + strlen("/objects"))
+	if (PATH_MAX <= super_len + strlen("/objects"))
 		die("Too long path: %.*s", 60, suspect);
-	strcpy(path, suspect);
+	strcpy(path, super);
 	if (getenv(DB_ENVIRONMENT)) {
 		if (access(getenv(DB_ENVIRONMENT), X_OK))
 			return 0;
 	}
 	else {
-		strcpy(path + len, "/objects");
+		strcpy(path + super_len, "/objects");
 		if (access(path, X_OK))
 			return 0;
 	}
 
-	strcpy(path + len, "/refs");
+	strcpy(path + super_len, "/refs");
 	if (access(path, X_OK))
 		return 0;
 
+	if (super != suspect)
+		strcpy(path, suspect);
 	strcpy(path + len, "/HEAD");
 	if (validate_headref(path))
 		return 0;
@@ -211,6 +214,12 @@ int is_git_directory(const char *suspect)
 	return 1;
 }
 
+int is_git_directory(const char *suspect)
+{
+	return is_git_directory_super(suspect, suspect);
+}
+
+
 int is_inside_git_dir(void)
 {
 	if (inside_git_dir < 0)
-- 
1.8.5.1.77.g42c48fa