Check errors from libgit2 calls
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/src/blame_git.c b/src/blame_git.c
index 0dae2d9..bff36c5 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);