Re: [PATCH v7 4/4] cat-file: add --batch-command mode
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 16, 2022, 03:00 UTC
- Message-ID
- <xmqq4k4zwm65.fsf@gitster.g>
- In-Reply-To
- <BE7471F8-0141-49ED-A34B-04D69BE18D96@gmail.com>
John Cai <johncai86@gmail.com> writes:
> Yeah, this is what I had before but there was discussion about > separation of concerns in [1]. But perhaps it's preferable > compared to passing a pointer to nr.
Oh, I see.
I do not see any issue with separation of concerns here, actually.
As long as "dispatch_calls() consumes all the cmd[] before it returns to the caller" is clearly understood between the function and its caller(s) [*], clearing of "nr" the caller has is entirely caller's problem. It becomes needed only because this caller decides to reuse cmd[] array.
Side note: you do have a comment before the function to tell what to expect out of the helper for its callers, right?
If it were just "accumulate many cmd[] and call the function once" caller, it would care to maintain the correct "nr" only up to the point where the function is called (because <cmd[], nr> pair is the way the function takes the list of commands and it needs a correct "nr"), but not after making the call, as the only thing left to do would be to free the cmd[] array itself, which does not even need "nr".