Skip to content

Commit 5f29433

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 40d9632 commit 5f29433

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ extern int is_nonbare_repository_dir(struct strbuf *path);
507507
#define READ_GITFILE_ERR_NO_PATH 6
508508
#define READ_GITFILE_ERR_NOT_A_REPO 7
509509
#define READ_GITFILE_ERR_TOO_LARGE 8
510+
extern void read_gitfile_error_die(int error_code, const char *path, const char *dir);
510511
extern const char *read_gitfile_gently(const char *path, int *return_error_code);
511512
#define read_gitfile(path) read_gitfile_gently((path), NULL)
512513
extern const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);

setup.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,30 @@ int verify_repository_format(const struct repository_format *format,
486486
return 0;
487487
}
488488

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+
489513
/*
490514
* Try to read the location of the git directory from the .git file,
491515
* return path to git directory if found.
@@ -559,28 +583,8 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
559583
cleanup_return:
560584
if (return_error_code)
561585
*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);
584588

585589
free(buf);
586590
return error_code ? NULL : path;

0 commit comments

Comments
 (0)