Skip to content

Commit 5452e49

Browse files
pks-ttiennou
authored andcommitted
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 parent c544850 commit 5452e49

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

src/attr.c

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -306,53 +306,47 @@ static int system_attr_file(
306306

307307
static int attr_setup(git_repository *repo, git_attr_session *attr_session)
308308
{
309-
int error = 0;
310-
const char *workdir = git_repository_workdir(repo);
311-
git_index *idx = NULL;
312309
git_buf path = GIT_BUF_INIT;
310+
git_index *idx = NULL;
311+
const char *workdir;
312+
int error = 0;
313313

314314
if (attr_session && attr_session->init_setup)
315315
return 0;
316316

317317
if ((error = git_attr_cache__init(repo)) < 0)
318318
return error;
319319

320-
/* preload attribute files that could contain macros so the
321-
* definitions will be available for later file parsing
320+
/*
321+
* Preload attribute files that could contain macros so the
322+
* definitions will be available for later file parsing.
322323
*/
323324

324-
error = system_attr_file(&path, attr_session);
325-
326-
if (error == 0)
327-
error = preload_attr_file(
328-
repo, attr_session, GIT_ATTR_FILE__FROM_FILE, NULL, path.ptr);
329-
330-
if (error != GIT_ENOTFOUND)
331-
goto out;
332-
333-
if ((error = preload_attr_file(
334-
repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
335-
NULL, git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
336-
goto out;
325+
if ((error = system_attr_file(&path, attr_session)) < 0 ||
326+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
327+
NULL, path.ptr)) < 0) {
328+
if (error != GIT_ENOTFOUND)
329+
goto out;
330+
}
337331

338-
if ((error = git_repository_item_path(&path,
339-
repo, GIT_REPOSITORY_ITEM_INFO)) < 0)
332+
if ((error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
333+
NULL, git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
340334
goto out;
341335

342-
if ((error = preload_attr_file(
343-
repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
344-
path.ptr, GIT_ATTR_FILE_INREPO)) < 0)
336+
if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
337+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
338+
path.ptr, GIT_ATTR_FILE_INREPO)) < 0)
345339
goto out;
346340

347-
if (workdir != NULL &&
348-
(error = preload_attr_file(
349-
repo, attr_session, GIT_ATTR_FILE__FROM_FILE, workdir, GIT_ATTR_FILE)) < 0)
350-
goto out;
341+
if ((workdir = git_repository_workdir(repo)) != NULL &&
342+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
343+
workdir, GIT_ATTR_FILE)) < 0)
344+
goto out;
351345

352346
if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
353-
(error = preload_attr_file(
354-
repo, attr_session, GIT_ATTR_FILE__FROM_INDEX, NULL, GIT_ATTR_FILE)) < 0)
355-
goto out;
347+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_INDEX,
348+
NULL, GIT_ATTR_FILE)) < 0)
349+
goto out;
356350

357351
if (attr_session)
358352
attr_session->init_setup = 1;

0 commit comments

Comments
 (0)