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>
Stefan Beller committed
Jan 24, 2017 at 15:56 UTC
5f29433f1ca1efc35d546a056200d923e86e3fca
2 files changed
+27
-22
cache.h
+1
@@ -507,6 +507,7 @@ extern int is_nonbare_repository_dir(struct strbuf *path);
507
#define READ_GITFILE_ERR_NO_PATH 6
508
#define READ_GITFILE_ERR_NOT_A_REPO 7
509
#define READ_GITFILE_ERR_TOO_LARGE 8
510
+extern void read_gitfile_error_die(int error_code, const char *path, const char *dir);
511
extern const char *read_gitfile_gently(const char *path, int *return_error_code);
512
#define read_gitfile(path) read_gitfile_gently((path), NULL)
513
extern const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
setup.c
+26
-22
@@ -486,6 +486,30 @@ int verify_repository_format(const struct repository_format *format,
486
return 0;
487
}
488
489
+void read_gitfile_error_die(int error_code, const char *path, const char *dir)
490
+{
491
+ switch (error_code) {
492
+ case READ_GITFILE_ERR_STAT_FAILED:
493
+ case READ_GITFILE_ERR_NOT_A_FILE:
494
+ /* non-fatal; follow return path */
495
+ break;
496
+ case READ_GITFILE_ERR_OPEN_FAILED:
497
+ die_errno("Error opening '%s'", path);
498
+ case READ_GITFILE_ERR_TOO_LARGE:
499
+ die("Too large to be a .git file: '%s'", path);
500
+ case READ_GITFILE_ERR_READ_FAILED:
501
+ die("Error reading %s", path);
502
+ case READ_GITFILE_ERR_INVALID_FORMAT:
503
+ die("Invalid gitfile format: %s", path);
504
+ case READ_GITFILE_ERR_NO_PATH:
505
+ die("No path in gitfile: %s", path);
506
+ case READ_GITFILE_ERR_NOT_A_REPO:
507
+ die("Not a git repository: %s", dir);
508
+ default:
509
+ die("BUG: unknown error code");
510
+ }
511
+}
512
+
513
/*
514
* Try to read the location of the git directory from the .git file,
515
* return path to git directory if found.
@@ -559,28 +583,8 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
583
cleanup_return:
584
if (return_error_code)
585
*return_error_code = error_code;
562
- else if (error_code) {
563
- switch (error_code) {
564
- case READ_GITFILE_ERR_STAT_FAILED:
565
- case READ_GITFILE_ERR_NOT_A_FILE:
566
- /* non-fatal; follow return path */
567
- break;
568
- case READ_GITFILE_ERR_OPEN_FAILED:
569
- die_errno("Error opening '%s'", path);
570
- case READ_GITFILE_ERR_TOO_LARGE:
571
- die("Too large to be a .git file: '%s'", path);
572
- case READ_GITFILE_ERR_READ_FAILED:
573
- die("Error reading %s", path);
574
- case READ_GITFILE_ERR_INVALID_FORMAT:
575
- die("Invalid gitfile format: %s", path);
576
- case READ_GITFILE_ERR_NO_PATH:
577
- die("No path in gitfile: %s", path);
578
- case READ_GITFILE_ERR_NOT_A_REPO:
579
- die("Not a git repository: %s", dir);
580
- default:
581
- assert(0);
582
- }
583
- }
586
+ else if (error_code)
587
+ read_gitfile_error_die(error_code, path, dir);
588
589
free(buf);
590
return error_code ? NULL : path;