git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "孙世龙 sunshilong" <sunshilong369@gmail.com>,
	"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: Fri, 17 Jul 2020 03:19:44 -0700	[thread overview]
Message-ID: <xmqq7dv2fnpb.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <xmqqd04ufutq.fsf@gitster.c.googlers.com> (Junio C. Hamano's message of "Fri, 17 Jul 2020 00:45:53 -0700")

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-17 10:19 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 [this message]
2020-07-18  4:51               ` 孙世龙 sunshilong
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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqq7dv2fnpb.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=sunshilong369@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).