Re: [PATCH 4/8] grep.c: move "prefix" out of "struct grep_opt"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Nov 08 2021, Taylor Blau wrote:

> On Sat, Nov 06, 2021 at 10:10:50PM +0100, Ævar Arnfjörð Bjarmason wrote:
>> 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_name
>
> But 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).

Yes, that would make much more sense. I just had tunnel vision while
writing this, evidently. Yeah, just either passing it or using a static
variable in grep.c would make more sense.

Arguably we could even have it be read only (const char *const) and have
a global "the_prefix" or something, but it's probably not widely used
enough for that to make sense.








[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux