return 0;
}
+void read_gitfile_error_die(int error_code, const char *path, const char *dir)
+{
+ switch (error_code) {
+ case READ_GITFILE_ERR_STAT_FAILED:
+ case READ_GITFILE_ERR_NOT_A_FILE:
+ /* non-fatal; follow return path */
+ break;
+ case READ_GITFILE_ERR_OPEN_FAILED:
+ die_errno("Error opening '%s'", path);
+ case READ_GITFILE_ERR_TOO_LARGE:
+ die("Too large to be a .git file: '%s'", path);
+ case READ_GITFILE_ERR_READ_FAILED:
+ die("Error reading %s", path);
+ case READ_GITFILE_ERR_INVALID_FORMAT:
+ die("Invalid gitfile format: %s", path);
+ case READ_GITFILE_ERR_NO_PATH:
+ die("No path in gitfile: %s", path);
+ case READ_GITFILE_ERR_NOT_A_REPO:
+ die("Not a git repository: %s", dir);
+ default:
+ die("BUG: unknown error code");
+ }
+}
+
/*
* Try to read the location of the git directory from the .git file,
* return path to git directory if found.
cleanup_return:
if (return_error_code)
*return_error_code = error_code;
- else if (error_code) {
- switch (error_code) {
- case READ_GITFILE_ERR_STAT_FAILED:
- case READ_GITFILE_ERR_NOT_A_FILE:
- /* non-fatal; follow return path */
- break;
- case READ_GITFILE_ERR_OPEN_FAILED:
- die_errno("Error opening '%s'", path);
- case READ_GITFILE_ERR_TOO_LARGE:
- die("Too large to be a .git file: '%s'", path);
- case READ_GITFILE_ERR_READ_FAILED:
- die("Error reading %s", path);
- case READ_GITFILE_ERR_INVALID_FORMAT:
- die("Invalid gitfile format: %s", path);
- case READ_GITFILE_ERR_NO_PATH:
- die("No path in gitfile: %s", path);
- case READ_GITFILE_ERR_NOT_A_REPO:
- die("Not a git repository: %s", dir);
- default:
- assert(0);
- }
- }
+ else if (error_code)
+ read_gitfile_error_die(error_code, path, dir);
free(buf);
return error_code ? NULL : path;
return setup_git_directory_gently(NULL);
}
-const char *resolve_gitdir(const char *suspect)
+const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)
{
if (is_git_directory(suspect))
return suspect;
- return read_gitfile(suspect);
+ return read_gitfile_gently(suspect, return_error_code);
}
/* if any standard file descriptor is missing open it to /dev/null */