Re: grep --no-index and pathspec

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

 



2011/2/12 Junio C Hamano <gitster@xxxxxxxxx>:
> This is a band-aid modelled after what builtin/clean.c does to the
> returned list from fill_directory(), and it seems to do its job, but I am
> quite unhappy about it.
>
> The function fill_directory() already takes a pathspec, albeit in the
> degenerate "const char **" form. ÂWhy does its output need further
> filtering?

Because it was designed so? Quotes from 9fc42d6 (Optimize directory
listing with pathspec limiter. - 2007-03-30), which added
simplify_away(), the function that does pathspec filtering for
fill_directory():

    NOTE! This does *not* obviate the need for the caller to do the *exact*
    pathspec match later. It's a first-level filter on "read_directory()", but
    it does not do the full pathspec thing. Maybe it should. But in the
    meantime, builtin-add.c really does need to do first

        read_directory(dir, .., pathspec);
        if (pathspec)
                prune_directory(dir, pathspec, baselen);

    ie the "prune_directory()" part will do the *exact* pathspec pruning,
    while the "read_directory()" will use the pathspec just to do some quick
    high-level pruning of the directories it will recurse into.

> @@ -626,6 +626,10 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec)
>
> Â Â Â Âfill_directory(&dir, pathspec->raw);
> Â Â Â Âfor (i = 0; i < dir.nr; i++) {
> + Â Â Â Â Â Â Â const char *name = dir.entries[i]->name;
> + Â Â Â Â Â Â Â int namelen = strlen(name);
> + Â Â Â Â Â Â Â if (!match_pathspec_depth(pathspec, name, namelen, 0, NULL))
> + Â Â Â Â Â Â Â Â Â Â Â continue;
> Â Â Â Â Â Â Â Âhit |= grep_file(opt, dir.entries[i]->name);
> Â Â Â Â Â Â Â Âif (hit && opt->status_only)
> Â Â Â Â Â Â Â Â Â Â Â Âbreak;

Looks good. We could move prune_directory() from builtin/add.c to
dir.c and use it here, but the gain is nothing (except noticing people
some pathspecs do not match any).
-- 
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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]