Re: [PATCH 4/8] grep.c: move "prefix" out of "struct grep_opt"
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Nov 8, 2021, 20:56 UTC
- Message-ID
- <YYmO9xlgFGhQlFZg@nand.local>
- In-Reply-To
- <patch-4.8-78298657d69-20211106T210711Z-avarab@gmail.com>
On Sat, Nov 06, 2021 at 10:10:50PM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 9 quoted lines
> The "struct grep_opt" is a mixture of things that would be needed by > all callers of the grep.c API, and quite a few things that only the > builtin/grep.c needs. > > Since we got rid of "prefix_length" in the previous commit, let's move > the "prefix" variable over to "builtin/grep.c" where it's used. To do > this let's create a "struct grep_cmd_opt", which we'll have a pointer > to in a new "caller_priv" member in "struct grep_opt" (the existing > "priv" is used by the top-level "grep.c" itself).
I'm definitely in favor of removing specialized, caller-specific bits from an internal API. But I'm not sure why grep.c needs to keep track o this new "caller_priv" field at all.
Among the uses of `prefix` in builtin/grep.c, I see grep_source_name, and the call to run_pager(). Would it be more straightforward to pass down prefix from cmd_grep down to its use in grep_source_name?
There are quite a few intermediary functions that we go through to get from cmd_grep() down to grep_source_name(). For instance, we could reach it through:
cmd_grep -> grep_tree -> grep_submodule -> grep_cache -> grep_oid ->
grep_source_nameBut passing prefix from cmd_grep down to grep_source_name without relying on the internals of grep.c seems like a good direction to me. I could even buy that (ab)using a static variable in builtin/grep.c to keep track of a constant prefix value would save you some plumbing (though I'd rather see the usage spelled out more explicitly).
All of that is to say that I share your motivation for this patch and think that the direction is good, but I would have preferred to do it without the caller_priv variable (unless there is something that I am missing here).
Thanks, Taylor