summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2017-01-24 15:56:50 -0800
committerJunio C Hamano <gitster@pobox.com>2017-01-26 11:00:58 -0800
commit5f29433f1ca1efc35d546a056200d923e86e3fca (patch)
treeb58a0f1092c359d2744a2cc415b02adb40f2eafc
parent40d96325143ae04cb3f645ac96f6413d1f641b9b (diff)
downloadgit-5f29433f1ca1efc35d546a056200d923e86e3fca.tar.gz
cache.h: expose the dying procedure for reading gitlinks
In a later patch we want to react to only a subset of errors, defaulting the rest to die as usual. Separate the block that takes care of dying into its own function so we have easy access to it. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--cache.h1
-rw-r--r--setup.c48
2 files changed, 27 insertions, 22 deletions
diff --git a/cache.h b/cache.h
index cafa3d10ae..d55f5dccb1 100644
--- a/cache.h
+++ b/cache.h
@@ -507,6 +507,7 @@ extern int is_nonbare_repository_dir(struct strbuf *path);
#define READ_GITFILE_ERR_NO_PATH 6
#define READ_GITFILE_ERR_NOT_A_REPO 7
#define READ_GITFILE_ERR_TOO_LARGE 8
+extern void read_gitfile_error_die(int error_code, const char *path, const char *dir);
extern const char *read_gitfile_gently(const char *path, int *return_error_code);
#define read_gitfile(path) read_gitfile_gently((path), NULL)
extern const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
diff --git a/setup.c b/setup.c
index 4605fd3c3c..967f289f1e 100644
--- a/setup.c
+++ b/setup.c
@@ -486,6 +486,30 @@ int verify_repository_format(const struct repository_format *format,
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.
@@ -559,28 +583,8 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
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;