cocci: add and apply free_commit_list() rules
Add and apply coccinelle rules to remove "if (E)" before "free_commit_list(E)", the function can accept NULL, and further change cases where "E = NULL" followed to also be unconditionally. The code changes in this commit were entirely made by the coccinelle rule being added here, and applied with: make contrib/coccinelle/free.cocci.patch patch -p1 <contrib/coccinelle/free.cocci.patch The only manual intervention here is that the the relevant code in commit.c has been manually re-indented. Suggested-by: Phillip Wood <phillip.wood123@gmail.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
89f45cf4eb
commit
bf20fe4ca8
@ -213,10 +213,8 @@ static void show_commit(struct commit *commit, void *data)
|
|||||||
|
|
||||||
static void finish_commit(struct commit *commit)
|
static void finish_commit(struct commit *commit)
|
||||||
{
|
{
|
||||||
if (commit->parents) {
|
|
||||||
free_commit_list(commit->parents);
|
free_commit_list(commit->parents);
|
||||||
commit->parents = NULL;
|
commit->parents = NULL;
|
||||||
}
|
|
||||||
free_commit_buffer(the_repository->parsed_objects,
|
free_commit_buffer(the_repository->parsed_objects,
|
||||||
commit);
|
commit);
|
||||||
}
|
}
|
||||||
|
3
commit.c
3
commit.c
@ -397,8 +397,6 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
|
|||||||
|
|
||||||
if (item->object.parsed)
|
if (item->object.parsed)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (item->parents) {
|
|
||||||
/*
|
/*
|
||||||
* Presumably this is leftover from an earlier failed parse;
|
* Presumably this is leftover from an earlier failed parse;
|
||||||
* clear it out in preparation for us re-parsing (we'll hit the
|
* clear it out in preparation for us re-parsing (we'll hit the
|
||||||
@ -407,7 +405,6 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
|
|||||||
*/
|
*/
|
||||||
free_commit_list(item->parents);
|
free_commit_list(item->parents);
|
||||||
item->parents = NULL;
|
item->parents = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
tail += size;
|
tail += size;
|
||||||
if (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, "tree ", 5) ||
|
if (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, "tree ", 5) ||
|
||||||
|
@ -2,13 +2,21 @@
|
|||||||
expression E;
|
expression E;
|
||||||
@@
|
@@
|
||||||
- if (E)
|
- if (E)
|
||||||
|
(
|
||||||
free(E);
|
free(E);
|
||||||
|
|
|
||||||
|
free_commit_list(E);
|
||||||
|
)
|
||||||
|
|
||||||
@@
|
@@
|
||||||
expression E;
|
expression E;
|
||||||
@@
|
@@
|
||||||
- if (!E)
|
- if (!E)
|
||||||
|
(
|
||||||
free(E);
|
free(E);
|
||||||
|
|
|
||||||
|
free_commit_list(E);
|
||||||
|
)
|
||||||
|
|
||||||
@@
|
@@
|
||||||
expression E;
|
expression E;
|
||||||
@ -16,3 +24,22 @@ expression E;
|
|||||||
- free(E);
|
- free(E);
|
||||||
+ FREE_AND_NULL(E);
|
+ FREE_AND_NULL(E);
|
||||||
- E = NULL;
|
- E = NULL;
|
||||||
|
|
||||||
|
@@
|
||||||
|
expression E;
|
||||||
|
@@
|
||||||
|
- if (E)
|
||||||
|
- {
|
||||||
|
free_commit_list(E);
|
||||||
|
E = NULL;
|
||||||
|
- }
|
||||||
|
|
||||||
|
@@
|
||||||
|
expression E;
|
||||||
|
statement S;
|
||||||
|
@@
|
||||||
|
- if (E) {
|
||||||
|
+ if (E)
|
||||||
|
S
|
||||||
|
free_commit_list(E);
|
||||||
|
- }
|
||||||
|
@ -1456,10 +1456,9 @@ static int limit_list(struct rev_info *revs)
|
|||||||
if (revs->left_only || revs->right_only)
|
if (revs->left_only || revs->right_only)
|
||||||
limit_left_right(newlist, revs);
|
limit_left_right(newlist, revs);
|
||||||
|
|
||||||
if (bottom) {
|
if (bottom)
|
||||||
limit_to_ancestry(bottom, newlist);
|
limit_to_ancestry(bottom, newlist);
|
||||||
free_commit_list(bottom);
|
free_commit_list(bottom);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if any commits have become TREESAME by some of their parents
|
* Check if any commits have become TREESAME by some of their parents
|
||||||
@ -4080,10 +4079,8 @@ static void create_boundary_commit_list(struct rev_info *revs)
|
|||||||
* boundary commits anyway. (This is what the code has always
|
* boundary commits anyway. (This is what the code has always
|
||||||
* done.)
|
* done.)
|
||||||
*/
|
*/
|
||||||
if (revs->commits) {
|
|
||||||
free_commit_list(revs->commits);
|
free_commit_list(revs->commits);
|
||||||
revs->commits = NULL;
|
revs->commits = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put all of the actual boundary commits from revs->boundary_commits
|
* Put all of the actual boundary commits from revs->boundary_commits
|
||||||
@ -4220,11 +4217,9 @@ struct commit *get_revision(struct rev_info *revs)
|
|||||||
graph_update(revs->graph, c);
|
graph_update(revs->graph, c);
|
||||||
if (!c) {
|
if (!c) {
|
||||||
free_saved_parents(revs);
|
free_saved_parents(revs);
|
||||||
if (revs->previous_parents) {
|
|
||||||
free_commit_list(revs->previous_parents);
|
free_commit_list(revs->previous_parents);
|
||||||
revs->previous_parents = NULL;
|
revs->previous_parents = NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,7 +664,6 @@ void show_submodule_diff_summary(struct diff_options *o, const char *path,
|
|||||||
print_submodule_diff_summary(sub, &rev, o);
|
print_submodule_diff_summary(sub, &rev, o);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (merge_bases)
|
|
||||||
free_commit_list(merge_bases);
|
free_commit_list(merge_bases);
|
||||||
clear_commit_marks(left, ~0);
|
clear_commit_marks(left, ~0);
|
||||||
clear_commit_marks(right, ~0);
|
clear_commit_marks(right, ~0);
|
||||||
@ -754,7 +753,6 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
if (merge_bases)
|
|
||||||
free_commit_list(merge_bases);
|
free_commit_list(merge_bases);
|
||||||
if (left)
|
if (left)
|
||||||
clear_commit_marks(left, ~0);
|
clear_commit_marks(left, ~0);
|
||||||
|
Loading…
Reference in New Issue
Block a user