All of lore.kernel.org
 help / color / mirror / Atom feed
From: "孙世龙 sunshilong" <sunshilong369@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, Carlo Arenas <carenas@gmail.com>,
	git@vger.kernel.org
Subject: Re: How can I search git log with ceratin keyword but without the other keyword?
Date: Sat, 18 Jul 2020 12:51:53 +0800	[thread overview]
Message-ID: <CAAvDm6bG-s2m9fGXVtuyLB7_FSDRduhb3ptrBsL3ezR9LaS-hQ@mail.gmail.com> (raw)
In-Reply-To: <xmqq7dv2fnpb.fsf@gitster.c.googlers.com>

Hi, Junio C Hamano

Thank you for your detailed explanation.

>There is not much room for the line-level "--not" operator to
>participate in this picture.
After I have carefully read your explanation again and again.
Maybe, I think there is a way to achieve this goal.
Please point out if there is something wrong.
For details, see below.

>"git grep -e X --not -e Y" would mean
>"find lines that has X, or that does not have Y", so as long as a
>document has one line with X on it and one line (which can be but
>does not have to be the same line) that does not have Y on it, the
>variant of that search with "--all-match" in it would say "yup the
>doc matches".  But that is definitely not what the user who wants to
>say "if a doc has X in it, I want to see it, but I do not want to
>see it if it also has Y" wants to see.
As you said in your last email, I think it(i.e. check out if a doc has X,
or that does not have Y) could be achieved by this way:
(Please point out if there is something wrong)
1. Split this goal into two parts, one is to find out whether this doc
   has X or not, the other one is whether this doc has Y or not, i.e.
   result = "doc has X" && "doc has no Y".
   We can run the grep machinery twice to achieve this goal.
2. As what you said in your last email, I have no much doubt about
    how to find out whether the doc has X or not. But, maybe, we can
    do some improvement.
    We can record the number of each line which matches the criteria(
    i.e. this line has X). We use "resX" to represent the result of this
    step(e.g: line 5,6,9,10 has X).
3. Check out whether each line matches the criteria(i.e. not have Y) or
    not and record the number of each line.
    We use "resY" to represent the result of this step(e.g. line 1, 5, 9,
    has no Y).
4. If resX is a non-empty set and resY is full set(i.e. contains all the
    line number) ,it implies that doc "have X and not have Y".

    Thank you for your attention to this matter.
    Best Regards.
    Sunshilong(孙世龙)

On Fri, Jul 17, 2020 at 6:19 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Jeff King <peff@peff.net> writes:
> >
> >> But none of that is exposed via the command-line of "git log". I think
> >> it would be possible to do so, but I'm not sure how tricky it would be
> >> (certainly one complication is that "--not" already means something else
> >> there, but presumably we could have "--grep-and", "--grep-not", etc).
> >
> > Perhaps the definition of "distant future" is about 8 years ;-)
> >
> > https://lore.kernel.org/git/7vr4q45y65.fsf@alter.siamese.dyndns.org/
>
> Having said that, I do not think our underlying grep machinery is
> equipped to answer "find every commit whose log message has X but
> not Y", even if we exposed the interface that is equivalent to that
> of "git grep" to "git log".
>
> There are two levels of boolean combination involved in running our
> "grep" machinery.  The lower level is used to determine if each line
> matches the criteria.  The main consumer of the "grep" machinery is
> of course "git grep" and because it is line oriented, we have quite
> a rich set of operations and combinations to say things like "if a
> line has X and Y on it in any order, but not Z on it, then the line
> is a match."  That is what "--not", "--and", "--or" (not exposed to
> the "git log" interface) express and we even take "(" and ")" for
> grouping, e.g. "( X --or Y ) --and --not Z".
>
> Another level of combination is to determine if the entire document
> matches.  It often happens that you want to find a document with
> both X and Y in it, and "grep -e X --and -e Y" is *NOT* a way to do
> so---the "--and" is a line-level combinator and tells the machinery
> to find lines that have both X and Y on them.
>
> We have a fairly ad-hoc single mechanism for boolean combination at
> this level and that is the "--all-match" option, which says "Look at
> the boolean expression you used to find each matching line, and
> separate them at the OR operator at the top level.  Now, apply the
> matching logic to all lines in a document and see if _all_ the
> clauses joined by the top-level OR operators matched at least once.
> If yes, then the document matches."
>
> That is how "git grep --all-match -e X -e Y" finds documents that
> refer to both X and Y but not necessarily on the same line.
>
> There is not much room for the line-level "--not" operator to
> participate in this picture.  "git grep -e X --not -e Y" would mean
> "find lines that has X, or that does not have Y", so as long as a
> document has one line with X on it and one line (which can be but
> does not have to be the same line) that does not have Y on it, the
> variant of that search with "--all-match" in it would say "yup the
> doc matches".  But that is definitely not what the user who wants to
> say "if a doc has X in it, I want to see it, but I do not want to
> see it if it also has Y" wants to see.
>
>
>
>
>
>

  reply	other threads:[~2020-07-18  4:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10  4:31 How can I search git log with ceratin keyword but without the other keyword? 孙世龙 sunshilong
2020-07-10  8:14 ` Carlo Arenas
2020-07-11  5:48   ` 孙世龙 sunshilong
2020-07-16 15:31     ` Jeff King
2020-07-17  1:45       ` 孙世龙 sunshilong
2020-07-17  6:33         ` Jeff King
2020-07-17  7:45           ` Junio C Hamano
2020-07-17 10:19             ` Junio C Hamano
2020-07-18  4:51               ` 孙世龙 sunshilong [this message]
2020-07-18 18:07                 ` Junio C Hamano
2020-07-19  5:28                   ` 孙世龙 sunshilong
2020-07-19  8:26                     ` Carlo Arenas
2020-07-20 17:50                       ` Junio C Hamano
2020-07-22  6:46                         ` Carlo Arenas
2020-07-17 10:27             ` 孙世龙 sunshilong
2020-07-17 10:42           ` 孙世龙 sunshilong
     [not found] <BYAPR21MB11587632058438090FE265B8E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com>
2020-12-27 23:45 ` Dan Moseley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAvDm6bG-s2m9fGXVtuyLB7_FSDRduhb3ptrBsL3ezR9LaS-hQ@mail.gmail.com \
    --to=sunshilong369@gmail.com \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.