git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git <git@vger.kernel.org>, Jonathan Nieder <jrnieder@gmail.com>
Subject: Re: [PATCH 1/1] diffcore: add a pickaxe option to find a specific blob
Date: Thu, 28 Dec 2017 13:43:36 -0800	[thread overview]
Message-ID: <CAGZ79kaB0G9zetF6QtC45+ZGLM3gOsYWV7e+gkCe2yKOhb0Ssg@mail.gmail.com> (raw)
In-Reply-To: <xmqqy3lmill0.fsf@gitster.mtv.corp.google.com>

On Thu, Dec 28, 2017 at 1:33 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> +static int parse_objfind_opt(struct diff_options *opt, const char *arg)
>> +{
>> +     struct object_id oid;
>> +
>> +     if (get_oid(arg, &oid))
>> +             return error("unable to resolve '%s'", arg);
>> +
>> +     if (!opt->objfind)
>> +             opt->objfind = xcalloc(1, sizeof(*opt->objfind));
>> +
>> +     opt->pickaxe = ""; /* trigger pickaxe */
>
> Hmmm.  This feels like an ugly hack to me.

Because it is.

$ git grep pickaxe diff.h
diff.h:94:      unsigned pickaxe_ignore_case:1;
diff.h:130:     const char *pickaxe;
diff.h:149:     int pickaxe_opts;
diff.h:361:"  --pickaxe-all\n" \

We could promote pickaxe_opts to be the important part
for pickaxing, currently we're using `pickaxe` in diff.c to
make a decision:

    if (options->pickaxe)
        diffcore_pickaxe(options);

So I think I'll cleanup the pickaxe_opts to be a real
unsigned flags field (such that pickaxe_ignore_case
could be part of it, too!) and put a new flag in
there in addition to DIFF_PICKAXE_KIND_{G, S}

> Do we declare that "git
> log -S''" never matches anything right now (if that is the case the
> I do not think there is any compatibility issues)?

Let's not go this route.


>
>> diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
>> index 9476bd2108..0d0c697ae7 100644
>> --- a/diffcore-pickaxe.c
>> +++ b/diffcore-pickaxe.c
>> @@ -124,13 +124,21 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
>>       mmfile_t mf1, mf2;
>>       int ret;
>>
>> -     if (!o->pickaxe[0])
>> -             return 0;
>> -
>>       /* ignore unmerged */
>>       if (!DIFF_FILE_VALID(p->one) && !DIFF_FILE_VALID(p->two))
>>               return 0;
>>
>> +     if (o->objfind) {
>> +             if ((DIFF_FILE_VALID(p->one) &&
>> +                  oidset_contains(o->objfind, &p->one->oid)) ||
>> +                 (DIFF_FILE_VALID(p->two) &&
>> +                  oidset_contains(o->objfind, &p->two->oid)))
>> +                     return 1;
>> +     }
>> +
>> +     if (!o->pickaxe[0])
>> +             return 0;
>> +
>
> Very nice.  With just one place, the code covers both cases with and
> without pickaxe-all option in effect.

and this is already fixed regarding the ugly hack, too.

Thanks,
Stefan

      reply	other threads:[~2017-12-28 21:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-28  0:00 [PATCH 0/1] Add blob find pickaxe option Stefan Beller
2017-12-28  0:00 ` [PATCH 1/1] diffcore: add a pickaxe option to find a specific blob Stefan Beller
2017-12-28 21:33   ` Junio C Hamano
2017-12-28 21:43     ` Stefan Beller [this message]

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=CAGZ79kaB0G9zetF6QtC45+ZGLM3gOsYWV7e+gkCe2yKOhb0Ssg@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@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).