Re: [PATCH 1/1] diffcore: add a pickaxe option to find a specific blob
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 28, 2017, 21:33 UTC
- Message-ID
- <xmqqy3lmill0.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20171228000003.34539-2-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 11 quoted lines
> +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. 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)?
Show 26 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.