Re: [PATCH v5 9/9] dir: introduce readdir_skip_dot_and_dotdot() helper
- From
Elijah Newren <newren@gmail.com>
- Date
- May 18, 2021, 03:34 UTC
- Message-ID
- <CABPp-BF7PrSK=yFvAVQe+vpNTv_j1ZTgh_HQeJVeGZeGk=499Q@mail.gmail.com>
- In-Reply-To
- <2b7ba27c-5ffa-0ef0-6c7a-4da45f979b9c@gmail.com>
On Mon, May 17, 2021 at 10:22 AM Derrick Stolee <stolee@gmail.com> wrote:
Show 30 quoted lines
>
> On 5/12/2021 1:28 PM, Elijah Newren via GitGitGadget wrote:
> > From: Elijah Newren <newren@gmail.com>
> >
> > Many places in the code were doing
> > while ((d = readdir(dir)) != NULL) {
> > if (is_dot_or_dotdot(d->d_name))
> > continue;
> > ...process d...
> > }
> > Introduce a readdir_skip_dot_and_dotdot() helper to make that a one-liner:
> > while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
> > ...process d...
> > }
> >
> > This helper particularly simplifies checks for empty directories.
> >
> > Also use this helper in read_cached_dir() so that our statistics are
> > consistent across platforms. (In other words, read_cached_dir() should
> > have been using is_dot_or_dotdot() and skipping such entries, but did
> > not and left it to treat_path() to detect and mark such entries as
> > path_none.)
>
> I like the idea of this helper!
>
> > +struct dirent *
> > +readdir_skip_dot_and_dotdot(DIR *dirp)
>
> nit: This seems like an accidental newline between the
> return type and the method name.I would fix this, but the patch is already in next. If Junio decides to revert the last two patches out of next because of the Signed-off-by issue on the previous patch, then I'll resubmit this patch as well with this issue fixed.