attr: refactor setup to match current coding style The code in the `attr_setup` function is not really matching our current coding style. Besides alignment issues, it's also hard to see what functions calls depend on one another because they're split up over multiple conditional statements. Fix these issues by grouping together dependent function calls and adjusting the alignment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/src/attr.c b/src/attr.c
index bd8e415..d9ddcfb 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -306,10 +306,10 @@ static int system_attr_file(
static int attr_setup(git_repository *repo, git_attr_session *attr_session)
{
- int error = 0;
- const char *workdir = git_repository_workdir(repo);
- git_index *idx = NULL;
git_buf path = GIT_BUF_INIT;
+ git_index *idx = NULL;
+ const char *workdir;
+ int error = 0;
if (attr_session && attr_session->init_setup)
return 0;
@@ -317,42 +317,36 @@ static int attr_setup(git_repository *repo, git_attr_session *attr_session)
if ((error = git_attr_cache__init(repo)) < 0)
return error;
- /* preload attribute files that could contain macros so the
- * definitions will be available for later file parsing
+ /*
+ * Preload attribute files that could contain macros so the
+ * definitions will be available for later file parsing.
*/
- error = system_attr_file(&path, attr_session);
-
- if (error == 0)
- error = preload_attr_file(
- repo, attr_session, GIT_ATTR_FILE__FROM_FILE, NULL, path.ptr);
-
- if (error != GIT_ENOTFOUND)
- goto out;
-
- if ((error = preload_attr_file(
- repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
- NULL, git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
- goto out;
+ if ((error = system_attr_file(&path, attr_session)) < 0 ||
+ (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
+ NULL, path.ptr)) < 0) {
+ if (error != GIT_ENOTFOUND)
+ goto out;
+ }
- if ((error = git_repository_item_path(&path,
- repo, GIT_REPOSITORY_ITEM_INFO)) < 0)
+ if ((error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
+ NULL, git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
goto out;
- if ((error = preload_attr_file(
- repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
- path.ptr, GIT_ATTR_FILE_INREPO)) < 0)
+ if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
+ (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
+ path.ptr, GIT_ATTR_FILE_INREPO)) < 0)
goto out;
- if (workdir != NULL &&
- (error = preload_attr_file(
- repo, attr_session, GIT_ATTR_FILE__FROM_FILE, workdir, GIT_ATTR_FILE)) < 0)
- goto out;
+ if ((workdir = git_repository_workdir(repo)) != NULL &&
+ (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
+ workdir, GIT_ATTR_FILE)) < 0)
+ goto out;
if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
- (error = preload_attr_file(
- repo, attr_session, GIT_ATTR_FILE__FROM_INDEX, NULL, GIT_ATTR_FILE)) < 0)
- goto out;
+ (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_INDEX,
+ NULL, GIT_ATTR_FILE)) < 0)
+ goto out;
if (attr_session)
attr_session->init_setup = 1;