Commit dbc7e4b1 by Patrick Steinhardt

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.
parent be8f9bb1
...@@ -345,33 +345,28 @@ int git_attr_file__lookup_one( ...@@ -345,33 +345,28 @@ int git_attr_file__lookup_one(
int git_attr_file__load_standalone(git_attr_file **out, const char *path) 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_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 = git_futils_readbuffer(&content, path)) < 0)
if (error < 0) goto out;
return error;
error = git_attr_cache__alloc_file_entry( /*
&file->entry, NULL, path, &file->pool); * Because the cache entry is allocated from the file's own pool, we
if (error < 0) {
git_attr_file__free(file);
return error;
}
/* 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. * don't have to free it - freeing file+pool will free cache entry, too.
*/ */
if (!(error = git_futils_readbuffer(&content, path))) { if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE__FROM_FILE)) < 0 ||
error = git_attr_file__parse_buffer(NULL, file, content.ptr); (error = git_attr_file__parse_buffer(NULL, file, content.ptr)) < 0 ||
git_buf_dispose(&content); (error = git_attr_cache__alloc_file_entry(&file->entry, NULL, path, &file->pool)) < 0)
} goto out;
*out = file;
out:
if (error < 0) if (error < 0)
git_attr_file__free(file); git_attr_file__free(file);
else git_buf_dispose(&content);
*out = file;
return error; return error;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment