]> git.ipfire.org Git - thirdparty/git.git/commit - revision.h
revision.[ch]: provide and start using a release_revisions()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 13 Apr 2022 20:01:35 +0000 (22:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Apr 2022 06:56:08 +0000 (23:56 -0700)
commit1878b5edc03c4bf685c7278fc4ced4704c876984
treec45566b464c5eeff933565d35224ac8ddd113055
parentbf20fe4ca8c8d2ba2087c9c44b4ee09a1d1467ed
revision.[ch]: provide and start using a release_revisions()

The users of the revision.[ch] API's "struct rev_info" are a major
source of memory leaks in the test suite under SANITIZE=leak, which in
turn adds a lot of noise when trying to mark up tests with
"TEST_PASSES_SANITIZE_LEAK=true".

The users of that API are largely one-shot, e.g. "git rev-list" or
"git log", or the "git checkout" and "git stash" being modified here

For these callers freeing the memory is arguably a waste of time, but
in many cases they've actually been trying to free the memory, and
just doing that in a buggy manner.

Let's provide a release_revisions() function for these users, and
start migrating them over per the plan outlined in [1]. Right now this
only handles the "pending" member of the struct, but more will be
added in subsequent commits.

Even though we only clear the "pending" member now, let's not leave a
trap in code like the pre-image of index_differs_from(), where we'd
start doing the wrong thing as soon as the release_revisions() learned
to clear its "diffopt". I.e. we need to call release_revisions() after
we've inspected any state in "struct rev_info".

This leaves in place e.g. clear_pathspec(&rev.prune_data) in
stash_working_tree() in builtin/stash.c, subsequent commits will teach
release_revisions() to free "prune_data" and other members that in
some cases are individually cleared by users of "struct rev_info" by
reaching into its members. Those subsequent commits will remove the
relevant calls to e.g. clear_pathspec().

We avoid amending code in index_differs_from() in diff-lib.c as well
as wt_status_collect_changes_index(), has_unstaged_changes() and
has_uncommitted_changes() in wt-status.c in a way that assumes that we
are already clearing the "diffopt" member. That will be handled in a
subsequent commit.

1. https://lore.kernel.org/git/87a6k8daeu.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
builtin/stash.c
diff-lib.c
range-diff.c
revision.c
revision.h
wt-status.c