Re: [PATCH v2 04/14] dir: select directories correctly
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Sep 15, 2021, 14:41 UTC
- Message-ID
- <3262acae-3ae1-7309-a1dd-b2e1472391a2@gmail.com>
- In-Reply-To
- <87h7ep5t5t.fsf@evledraar.gmail.com>
On 9/12/2021 6:21 PM, Ævar Arnfjörð Bjarmason wrote:
Show 13 quoted lines
>
> On Sun, Sep 12 2021, Derrick Stolee via GitGitGadget wrote:
>
>> + /*
>> + * Use 'alloc' as an indicator that the string has not been
>> + * initialized, in case the parent is the root directory.
>> + */
>> + if (!path_parent->alloc) {
>
> This isn't wrong, but seems to be way too cozy with the internal
> implementation details of strbuf. For what it's worth I renamed it to
> "alloc2" and found that this would be only the 3rd bit of code out of
> strbuf.[ch] that cares about that member.I can understand not wanting to poke into the internals.
Show 5 quoted lines
>> + char *slash; >> + strbuf_addstr(path_parent, pathname); > > So is "pathname" ever the empty string? If not we could check the > length?
We are given 'pathlen' as a parameter, so this should just use strbuf_add() instead.
Show 11 quoted lines
> Or probably better: ...
>
>> @@ -1331,6 +1359,7 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname
>> {
>> struct path_pattern *res = NULL; /* undecided */
>> int i;
>> + struct strbuf path_parent = STRBUF_INIT;
>
> Just malloc + strbuf_init() this in the above function and have a
> "struct strbuf *" initialized to NULL here? Then we can use a much more
> idiomatic "is it NULL?" to check if it's initialized.That makes sense. Can do.
Thanks, -Stolee