summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-09-21 22:01:53 -0700
committerBen Straub <bs@github.com>2013-09-21 22:01:53 -0700
commit77db6ff5c7b5a233b6dae24347b660f2752c1359 (patch)
tree5aaa07874a4a8e582d9ac3f3c0fb2403c0926991 /src
parentf0c9d8ba1c7b9a5913248ea5228700da2eb76aaa (diff)
downloadlibgit2-77db6ff5c7b5a233b6dae24347b660f2752c1359.tar.gz
Simplify blob loading logic
Diffstat (limited to 'src')
-rw-r--r--src/blame.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/blame.c b/src/blame.c
index ccfbb1ee7..ed816da52 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -256,6 +256,22 @@ static git_blame_hunk* hunk_from_entry(git_blame__entry *e)
return h;
}
+static int load_blob(git_blame *blame)
+{
+ int error;
+
+ error = git_commit_lookup(&blame->final, blame->repository, &blame->options.newest_commit);
+ if (error < 0)
+ goto cleanup;
+ error = git_object_lookup_bypath((git_object**)&blame->final_blob,
+ (git_object*)blame->final, blame->path, GIT_OBJ_BLOB);
+ if (error < 0)
+ goto cleanup;
+
+cleanup:
+ return error;
+}
+
static int blame_internal(git_blame *blame)
{
int error;
@@ -309,27 +325,6 @@ cleanup:
* File blaming
******************************************************************************/
-static int load_blob(git_blame *blame, git_repository *repo, git_oid *commit_id, const char *path)
-{
- int retval = -1;
- git_commit *commit = NULL;
- git_tree *tree = NULL;
- git_tree_entry *tree_entry = NULL;
- git_object *obj = NULL;
-
- if (((retval = git_commit_lookup(&commit, repo, commit_id)) < 0) ||
- ((retval = git_object_lookup_bypath(&obj, (git_object*)commit, path, GIT_OBJ_BLOB)) < 0) ||
- ((retval = git_object_type(obj)) != GIT_OBJ_BLOB))
- goto cleanup;
- blame->final_blob = (git_blob*)obj;
-
-cleanup:
- git_tree_entry_free(tree_entry);
- git_tree_free(tree);
- git_commit_free(commit);
- return retval;
-}
-
int git_blame_file(
git_blame **out,
git_repository *repo,
@@ -346,7 +341,7 @@ int git_blame_file(
blame = git_blame__alloc(repo, normOptions, path);
GITERR_CHECK_ALLOC(blame);
- if ((error = load_blob(blame, repo, &normOptions.newest_commit, path)) < 0)
+ if ((error = load_blob(blame)) < 0)
goto on_error;
if ((error = blame_internal(blame)) < 0)