From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 374E31F4B4 for ; Mon, 12 Oct 2020 18:01:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404122AbgJLSBK (ORCPT ); Mon, 12 Oct 2020 14:01:10 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:57175 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404069AbgJLSBK (ORCPT ); Mon, 12 Oct 2020 14:01:10 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 12CCF8C935; Mon, 12 Oct 2020 14:01:05 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=/YVbtyrOvhqt hmZqobMDKJuDvO4=; b=tSlbHkoj3ULJZf46XvIQIqZ/tLUUjkWunLtPiOctNcOq 0zuPRWhpcC+rqA7e7f7XT8gGqpDA0FjwKH7/JB/x/Qxd603964VEeL+XE1sZLEVb HjkmcN1BMi5jrsxT1DU+Iw+pynf8ZRthD9eWQ5WfR9LngorXkDaLUXphve+FVW8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=sasl; b=jgOYmN eLRgQqU2jO0LafFv5j0m2sKDFxsxcgVyFFyDE4HaYtoWnCZfQgYCMEBV6WxM9i+8 BJoye/mZ4YgRcqkmHuLxB70fJMUfHLc2TIsVZCOR4h2N+OqhFz8Hev5oi+qrDUa6 vXkSO6vnKzLdbZ6nDJKQP3+rKS+k3GxVJUsrs= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 033808C934; Mon, 12 Oct 2020 14:01:05 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.74.119.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 527A48C933; Mon, 12 Oct 2020 14:01:03 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: =?utf-8?B?TWljaGHFgiBLxJlwaWXFhA==?= Cc: git@vger.kernel.org Subject: Re: [PATCH v2 2/3] diff: add -I that ignores matching changes References: <20201001120606.25773-1-michal@isc.org> <20201012091751.19594-1-michal@isc.org> <20201012091751.19594-3-michal@isc.org> Date: Mon, 12 Oct 2020 11:01:02 -0700 In-Reply-To: <20201012091751.19594-3-michal@isc.org> (=?utf-8?B?Ik1pY2hh?= =?utf-8?B?xYIgS8SZcGllxYQiJ3M=?= message of "Mon, 12 Oct 2020 11:17:50 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Pobox-Relay-ID: E49E1910-0CB4-11EB-A435-D152C8D8090B-77302942!pb-smtp1.pobox.com Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Micha=C5=82 K=C4=99pie=C5=84 writes: > Add a new diff option that enables ignoring changes whose all lines > (changed, removed, and added) match a given regular expression. This i= s > similar to the -I option in standalone diff utilities and can be used > e.g. to ignore changes which only affect code comments or to look for > unrelated changes in commits containing a large number of automatically > applied modifications (e.g. a tree-wide string replacement). The > difference between -G/-S and the new -I option is that the latter > filters output on a per-change basis. > > Use the 'ignore' field of xdchange_t for marking a change as ignored or > not. Since the same field is used by --ignore-blank-lines, identical > hunk emitting rules apply for --ignore-blank-lines and -I. These two > options can also be used together in the same git invocation (they are > complementary to each other). > > Rename xdl_mark_ignorable() to xdl_mark_ignorable_lines(), to indicate > that it is logically a "sibling" of xdl_mark_ignorable_regex() rather > than its "parent". > > Signed-off-by: Micha=C5=82 K=C4=99pie=C5=84 Well explained. > +-I:: Since we are mimicking other folks' feature, giving also the --ignore-matching-lines=3D synonym to that their users are familiar with would be a good idea, no? > + Ignore changes whose all lines match . This option may > + be specified more than once. > + > --inter-hunk-context=3D:: > Show the context between diff hunks, up to the specified number > of lines, thereby fusing hunks that are close to each other. > diff --git a/diff.c b/diff.c > index 2bb2f8f57e..c5d4920fee 100644 > --- a/diff.c > +++ b/diff.c > @@ -3587,6 +3587,8 @@ static void builtin_diff(const char *name_a, > if (header.len && !o->flags.suppress_diff_headers) > ecbdata.header =3D &header; > xpp.flags =3D o->xdl_opts; > + xpp.ignore_regex =3D o->ignore_regex; > + xpp.ignore_regex_nr =3D o->ignore_regex_nr; > xpp.anchors =3D o->anchors; > xpp.anchors_nr =3D o->anchors_nr; > xecfg.ctxlen =3D o->context; > @@ -3716,6 +3718,8 @@ static void builtin_diffstat(const char *name_a, = const char *name_b, > memset(&xpp, 0, sizeof(xpp)); > memset(&xecfg, 0, sizeof(xecfg)); > xpp.flags =3D o->xdl_opts; > + xpp.ignore_regex =3D o->ignore_regex; > + xpp.ignore_regex_nr =3D o->ignore_regex_nr; > xpp.anchors =3D o->anchors; > xpp.anchors_nr =3D o->anchors_nr; > xecfg.ctxlen =3D o->context; > @@ -5203,6 +5207,22 @@ static int diff_opt_patience(const struct option= *opt, > return 0; > } > =20 > +static int diff_opt_ignore_regex(const struct option *opt, > + const char *arg, int unset) > +{ > + struct diff_options *options =3D opt->value; > + regex_t *regex; > + > + BUG_ON_OPT_NEG(unset); > + regex =3D xcalloc(1, sizeof(*regex)); > + if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) > + die("invalid regex: %s", arg); > + ALLOC_GROW(options->ignore_regex, options->ignore_regex_nr + 1, > + options->ignore_regex_alloc); > + options->ignore_regex[options->ignore_regex_nr++] =3D regex; > + return 0; > +} Don't these parse-options callback functions have a way to tell the caller die instead of them themselves dying like this? Would it work better to "return error(... message ...)", or would that give two error messages? In anycase, this is end-user facing, so we'd want it to be localizable, e.g. die(_("invalid regexp given to -I: '%s'", arg)); probably. > static int diff_opt_pickaxe_regex(const struct option *opt, > const char *arg, int unset) > { Other than that, nicely done. Thanks.