Re: [PATCH 1/3] builtin/commit-graph.c: support '--split[=<strategy>]'
- From
Jeff King <peff@peff.net>
- Date
- Feb 4, 2020, 14:14 UTC
- Message-ID
- <20200204141441.GA563710@coredump.intra.peff.net>
- In-Reply-To
- <20200204035821.GB5790@syl.local>
On Mon, Feb 03, 2020 at 07:58:21PM -0800, Taylor Blau wrote:
Show 26 quoted lines
> I think that this seems like a good step that we should probably take,
> but I don't think that it's necessary for the series at hand. The
> pattern in this function is to define a local variable which has the
> same value as in split_opts, or a reasonable default if split_opts is
> NULL (c.f., 'max_commits' and 'size_mult').
>
> So, I think that a safe thing to do which prevents the segv and doesn't
> change the pattern too much is to write:
>
> enum commit_graph_split_flags flags = COMMIT_GRAPH_SPLIT_MERGE_AUTO;
> if (ctx->split_opts) {
> /* ... */
> flags = ctx->split_opts->flags;
> }
>
> /* ... */
>
> if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED) {
> while ( ... ) { ... }
> }
>
> This is adding another local variable, which seems like an odd thing to
> do *every* time that we add another member to split_opts. So for that
> reason it seems like in the longer-term we should either force the
> caller to pass in a blank, or do something else that doesn't require
> this, but I think that the intermediate cost isn't too bad.It would perhaps be simpler to turn NULL into a _single_ default-filled split_opts variable, and then just use it throughout the function. And since presumably zero-initialization would yield good defaults (or we'd define an INIT macro for the convenience of callers), it would be a one-liner that we'd only have to do once.
But I think that can wait; the "if" solution discussed seems like a straightforward way to make this patch correct both on top of master, and when merged with next.
-Peff