Re: [PATCH v2 04/14] dir: select directories correctly
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Sep 12, 2021, 22:21 UTC
- Message-ID
- <87h7ep5t5t.fsf@evledraar.gmail.com>
- In-Reply-To
- <723de4e42582afbe841ed96470fc02db44b24b5e.1631453010.git.gitgitgadget@gmail.com>
On Sun, Sep 12 2021, Derrick Stolee via GitGitGadget wrote:
Show 5 quoted lines
> + /*
> + * 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.
> + char *slash; > + strbuf_addstr(path_parent, pathname);
So is "pathname" ever the empty string? If not we could check the length?
Or probably better: ...
Show 5 quoted lines
> @@ -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.