Subject: Re: [PATCH v3 08/27] revisions API users: add "goto cleanup" for "rev_info" early exit

From: Junio C Hamano <[email-masked]>
Date: Fri, 25 Mar 2022 22:24:30 -0700

Ævar Arnfjörð Bjarmason <[email-masked]> writes:

> Because I don't see how it makes any sense to have a REV_INFO_INIT if it
> doesn't actually give you an init'd "struct rev_info" that's ready for
> use. I.e. if you still need to call repo_init_revisions() it's just a
> misleading interface.

You can say

	struct something *foo = NULL;

	if (some condition)
		foo = alloc_and_init_foo();

	...

	free_and_destruct(foo);

and it is correct that "initialize with NULL" alone would not let
you use the thing as full fledged 'foo', but you can still safely
pass it to free_and_destruct() (or if "something" does not hold
external resources, it could just be free()).  A flow like this:

	struct rev_info revs = REV_INFO_INIT;

	if (!some condition)
		goto leave;
	init(&revs);
	... use revs ...
leave:
        release(&revs);

would exactly be the same thing.

In other words, you say "I do not see how it makes any sense" but to
me it looks more like what does not make sense is your argument
against what was suggested.