git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1] diffcore: add a pickaxe option to find a specific blob

From
Stefan Beller <sbeller@google.com>
Date
Dec 28, 2017, 21:43 UTC
Message-ID
<CAGZ79kaB0G9zetF6QtC45+ZGLM3gOsYWV7e+gkCe2yKOhb0Ssg@mail.gmail.com>
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:
Show 15 quoted lines
> 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.
Show 30 quoted lines
>
>> 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

Previous: Junio C Hamano
Message 4 of 4 in “Add blob find pickaxe option”
  1. 0/1 Add blob find pickaxe optionStefan Beller, Dec 28, 2017
  2. 1/1 diffcore: add a pickaxe option to find a specific blobStefan Beller, Dec 28, 2017
  3. Junio C HamanoDec 28, 2017
  4. Stefan BellerDec 28, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.