]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-fast-rebase helper: use release_revisions() (again)
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 2 Aug 2022 15:33:12 +0000 (17:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Aug 2022 17:13:50 +0000 (10:13 -0700)
Fix a bug in 0139c58ab95 (revisions API users: add "goto cleanup" for
release_revisions(), 2022-04-13), in that commit a release_revisions()
call was added to this function, but it never did anything due to this
TODO memset() added in fe1a21d5267 (fast-rebase: demonstrate
merge-ort's API via new test-tool command, 2020-10-29).

Simply removing the memset() will fix the "cmdline" which can be seen
when running t5520-pull.sh.

This sort of thing could be detected automatically with a rule similar
to the unused.cocci merged in 7fa60d2a5b6 (Merge branch
'ab/cocci-unused' into next, 2022-07-11). The following rule on top
would catch the case being fixed here:

@@
type T;
identifier I;
identifier REL1 =~ "^[a-z_]*_(release|reset|clear|free)$";
identifier REL2 =~ "^(release|clear|free)_[a-z_]*$";
@@

- memset(\( I \| &I \), 0, ...);
  ... when != \( I \| &I \)
(
  \( REL1 \| REL2 \)( \( I \| &I \), ...);
|
  \( REL1 \| REL2 \)( \( &I \| I \) );
)
  ... when != \( I \| &I \)

That rule should arguably use only &I, not I (as we might be passed a
pointer). The distinction would matter if anyone cared about the
side-effects of a memset() followed by release() of a pointer to a
variable passed into the function.

As such a pattern would be at best very confusing, and most likely
point to buggy code as in this case, the above rule is probably fine
as-is.

But as this rule only found one such bug in the entire codebase let's
not add it to contrib/coccinelle/unused.cocci for now, we can always
dig it up in the future if it's deemed useful.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/helper/test-fast-rebase.c

index 4e5553e20249debf36a76296f18599300ee91af5..45665ec19a5d6d4e2cf37c1a2a9f87d69ff3be02 100644 (file)
@@ -184,8 +184,6 @@ int cmd__fast_rebase(int argc, const char **argv)
                last_picked_commit = commit;
                last_commit = create_commit(result.tree, commit, last_commit);
        }
-       /* TODO: There should be some kind of rev_info_free(&revs) call... */
-       memset(&revs, 0, sizeof(revs));
 
        merge_switch_to_result(&merge_opt, head_tree, &result, 1, !result.clean);