From 0afe9996483387d282821958974320078923306c Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 17 Sep 2013 16:46:27 -0700 Subject: [PATCH] Check errors from libgit2 calls --- src/blame_git.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/blame_git.c b/src/blame_git.c index 0dae2d9c1..bff36c50c 100644 --- a/src/blame_git.c +++ b/src/blame_git.c @@ -374,9 +374,9 @@ static struct origin* find_origin(struct scoreboard *sb, git_commit *parent, git_tree *otree=NULL, *ptree=NULL; /* Get the trees from this commit and its parent */ - // TODO: check errors - git_commit_tree(&otree, origin->commit); - git_commit_tree(&ptree, parent); + if (0 != git_commit_tree(&otree, origin->commit) || + 0 != git_commit_tree(&ptree, parent)) + goto cleanup; /* Configure the diff */ diffopts.context_lines = 0; @@ -385,12 +385,11 @@ static struct origin* find_origin(struct scoreboard *sb, git_commit *parent, /* Check to see if files we're interested have changed */ diffopts.pathspec.count = sb->blame->paths.length; diffopts.pathspec.strings = (char**)sb->blame->paths.contents; - // TODO: check error - git_diff_tree_to_tree(&difflist, sb->blame->repository, ptree, otree, &diffopts); + if (0 != git_diff_tree_to_tree(&difflist, sb->blame->repository, ptree, otree, &diffopts)) + goto cleanup; if (!git_diff_num_deltas(difflist)) { /* No changes; copy data */ - // TODO: check error get_origin(&porigin, sb, parent, origin->path); } else { git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT; @@ -399,13 +398,13 @@ static struct origin* find_origin(struct scoreboard *sb, git_commit *parent, /* Generate a full diff between the two trees */ git_diff_list_free(difflist); diffopts.pathspec.count = 0; - // TODO: check error - git_diff_tree_to_tree(&difflist, sb->blame->repository, ptree, otree, &diffopts); + if (0 != git_diff_tree_to_tree(&difflist, sb->blame->repository, ptree, otree, &diffopts)) + goto cleanup; /* Let diff find renames */ findopts.flags = GIT_DIFF_FIND_RENAMES; - // TODO: check error - git_diff_find_similar(difflist, &findopts); + if (0 != git_diff_find_similar(difflist, &findopts)) + goto cleanup; /* Find one that matches */ for (i=0; i<(int)git_diff_num_deltas(difflist); i++) { @@ -415,16 +414,15 @@ static struct origin* find_origin(struct scoreboard *sb, git_commit *parent, continue; git_vector_insert_sorted(&sb->blame->paths, (void*)git__strdup(delta->old_file.path), paths_on_dup); - // TODO: check error make_origin(&porigin, parent, delta->old_file.path); } } +cleanup: git_diff_list_free(difflist); git_tree_free(otree); git_tree_free(ptree); return porigin; - } /* @@ -472,7 +470,6 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, uint32_t op if (sg_origin[i]) continue; - // TODO: check error git_commit_parent(&p, origin->commit, i); porigin = find_origin(sb, p, origin);