diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-07-05 07:53:02 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-07-12 09:26:22 +0200 |
commit | dbc7e4b1506f9de897120d904e51cb0134e0006a (patch) | |
tree | 0ef6d772571e96b16fe026d35d0d4a51ddbe41ad | |
parent | be8f9bb188668cb1f1976f28f2aa4fef9e74890a (diff) | |
download | libgit2-dbc7e4b1506f9de897120d904e51cb0134e0006a.tar.gz |
attr_file: refactor `load_standalone` function
The gitattributes code is one of our oldest and most-untouched codebases
in libgit2, and as such its code style doesn't quite match our current
best practices. Refactor the function `git_attr_file__lookup_standalone`
to better match them.
-rw-r--r-- | src/attr_file.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/attr_file.c b/src/attr_file.c index 55838370c..4fa3d9652 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -345,33 +345,28 @@ int git_attr_file__lookup_one( int git_attr_file__load_standalone(git_attr_file **out, const char *path) { - int error; - git_attr_file *file; git_buf content = GIT_BUF_INIT; + git_attr_file *file = NULL; + int error; - error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE__FROM_FILE); - if (error < 0) - return error; + if ((error = git_futils_readbuffer(&content, path)) < 0) + goto out; - error = git_attr_cache__alloc_file_entry( - &file->entry, NULL, path, &file->pool); - if (error < 0) { - git_attr_file__free(file); - return error; - } - /* because the cache entry is allocated from the file's own pool, we + /* + * Because the cache entry is allocated from the file's own pool, we * don't have to free it - freeing file+pool will free cache entry, too. */ - if (!(error = git_futils_readbuffer(&content, path))) { - error = git_attr_file__parse_buffer(NULL, file, content.ptr); - git_buf_dispose(&content); - } + if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE__FROM_FILE)) < 0 || + (error = git_attr_file__parse_buffer(NULL, file, content.ptr)) < 0 || + (error = git_attr_cache__alloc_file_entry(&file->entry, NULL, path, &file->pool)) < 0) + goto out; + *out = file; +out: if (error < 0) git_attr_file__free(file); - else - *out = file; + git_buf_dispose(&content); return error; } |