All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Michael J Gruber <git@drmicha.warpmail.net>
Cc: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
	git@vger.kernel.org, jeremy.rosen@openwide.fr,
	Jeff King <peff@peff.net>
Subject: Re: [PATCHv2 7/7] git grep: honor textconv by default
Date: Mon, 29 Apr 2013 08:04:56 -0700	[thread overview]
Message-ID: <7vy5c1l6nb.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <517E37A9.8040609@drmicha.warpmail.net> (Michael J. Gruber's message of "Mon, 29 Apr 2013 11:04:41 +0200")

Michael J Gruber <git@drmicha.warpmail.net> writes:

>> It should be possible to have a tri-state for the --[no-]textconv
>> option: unset, set to true or set to false. But the code sharing between
>> log, show and diff might make that non-trivial.
>
> Right now it's a diffopt bit...

I wonder if you can do something along the lines of the attached
patch.  The following discussion assumes that your default wants
textconv for generating patches, and no textconv for showing blobs,
which is the case your "it is a bit" becomes an issue.

The basic structure is that:

 * There is an extra "opt->touched_flags" that keeps track of all
   the fields that have been touched by DIFF_OPT_SET and
   DIFF_OPT_CLR;

 * You may continue setting the default values to the flags, like
   commands in the "log" family do in cmd_log_init_defaults(), but
   after you finished setting the defaults, you clear the
   touched_flags field;

 * And then you let the usual callchain to call diff_opt_parse(),
   allowing the opt->flags be set or unset, while keeping track of
   which bits the user touched;

 * There is an optional callback "opt->set_default" that is called
   at the very beginning to lets you inspect touched_flags and
   update opt->flags appropriately, before the remainder of the
   diffcore machinery is set up, taking the opt->flags value into
   account.

Your "git show" could start out with ALLOW_TEXTCONV set, but notice
explicit requests to --[no-]textconv from the command line in your
set_default() callback.  And then when it deals with a blob, check
if the user touched ALLOW_TEXTCONV and appropriately act on that
knowledge.

There would be three cases in your set_default callback:

 * flags has ALLOW_TEXTCONV set, and the bit was touched: the user
   explicitly said --textconv because she wants blobs to be mangled;

 * flags has ALLOW_TEXTCONV set, and the bit was not touched: the
   user did not say --textconv; do not mangle blobs;

 * flags has ALLOW_TEXTCONV unset; the user did not say --textconv,
   or explicitly said --no-textconv; do not mangle blobs.

The set_default callback can also be used to adjust defaults for
fields that are not handled by the DIFF_OPT_SET/CLR/TST, by the way.
You can remember the address of the default value you fed to a
string field before entering the callchain to diff_opt_parse(), and
in your set_default callback see if the value is still pointing at
the same piece of memory (in which case the user did not touch it).

 builtin/log.c | 1 +
 diff.c        | 3 +++
 diff.h        | 7 +++++--
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 6e56a50..c62ecd1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -91,6 +91,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
 
 	if (default_date_mode)
 		rev->date_mode = parse_date_format(default_date_mode);
+	rev->diffopt.touched_flags = 0;
 }
 
 static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
diff --git a/diff.c b/diff.c
index f0b3e7c..7c24872 100644
--- a/diff.c
+++ b/diff.c
@@ -3213,6 +3213,9 @@ void diff_setup_done(struct diff_options *options)
 {
 	int count = 0;
 
+	if (options->set_default)
+		options->set_default(options);
+
 	if (options->output_format & DIFF_FORMAT_NAME)
 		count++;
 	if (options->output_format & DIFF_FORMAT_NAME_STATUS)
diff --git a/diff.h b/diff.h
index 78b4091..5c2f878 100644
--- a/diff.h
+++ b/diff.h
@@ -87,8 +87,8 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 #define DIFF_OPT_PICKAXE_IGNORE_CASE (1 << 30)
 
 #define DIFF_OPT_TST(opts, flag)    ((opts)->flags & DIFF_OPT_##flag)
-#define DIFF_OPT_SET(opts, flag)    ((opts)->flags |= DIFF_OPT_##flag)
-#define DIFF_OPT_CLR(opts, flag)    ((opts)->flags &= ~DIFF_OPT_##flag)
+#define DIFF_OPT_SET(opts, flag)    (((opts)->flags |= DIFF_OPT_##flag),((opts)->touched_flags |= DIFF_OPT_##flag))
+#define DIFF_OPT_CLR(opts, flag)    (((opts)->flags &= ~DIFF_OPT_##flag),((opts)->touched_flags |= DIFF_OPT_##flag))
 #define DIFF_XDL_TST(opts, flag)    ((opts)->xdl_opts & XDF_##flag)
 #define DIFF_XDL_SET(opts, flag)    ((opts)->xdl_opts |= XDF_##flag)
 #define DIFF_XDL_CLR(opts, flag)    ((opts)->xdl_opts &= ~XDF_##flag)
@@ -109,6 +109,7 @@ struct diff_options {
 	const char *single_follow;
 	const char *a_prefix, *b_prefix;
 	unsigned flags;
+	unsigned touched_flags;
 	int use_color;
 	int context;
 	int interhunkcontext;
@@ -145,6 +146,8 @@ struct diff_options {
 	/* to support internal diff recursion by --follow hack*/
 	int found_follow;
 
+	void (*set_default)(struct diff_options *);
+
 	FILE *file;
 	int close_file;
 

  reply	other threads:[~2013-04-29 15:05 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-19 16:44 [PATCH 0/6] grep with textconv Michael J Gruber
2013-04-19 16:44 ` [PATCH 1/6] t4030: demonstrate behavior of show " Michael J Gruber
2013-04-20  4:04   ` Jeff King
2013-04-20 13:35     ` Michael J Gruber
2013-04-19 16:44 ` [PATCH 2/6] show: obey --textconv for blobs Michael J Gruber
2013-04-20  4:06   ` Jeff King
2013-04-20 13:38     ` Michael J Gruber
2013-04-21  3:37       ` Jeff King
2013-04-22 10:29         ` Michael J Gruber
2013-04-22 15:25         ` Junio C Hamano
2013-04-22 15:29           ` Jeff King
2013-04-22 15:37             ` Jeremy Rosen
2013-04-22 15:54               ` Matthieu Moy
2013-04-23  8:58                 ` Michael J Gruber
2013-04-19 16:44 ` [PATCH 3/6] cat-file: do not die on --textconv without textconv filters Michael J Gruber
2013-04-19 18:15   ` Junio C Hamano
2013-04-20  4:17   ` Jeff King
2013-04-20 14:27     ` Michael J Gruber
2013-04-19 16:44 ` [PATCH 4/6] t7008: demonstrate behavior of grep with textconv Michael J Gruber
2013-04-19 16:44 ` [PATCH 5/6] grep: allow to use textconv filters Michael J Gruber
2013-04-20  4:31   ` Jeff King
2013-04-19 16:44 ` [PATCH 6/6] grep: obey --textconv for the case rev:path Michael J Gruber
2013-04-20  4:24   ` Jeff King
2013-04-20 14:42     ` Michael J Gruber
2013-04-21  3:41       ` Jeff King
2013-04-19 18:24 ` [PATCH 0/6] grep with textconv Junio C Hamano
2013-04-20  4:26   ` Jeff King
2013-04-20 13:32   ` Michael J Gruber
2013-04-23 12:11     ` [PATCHv2 0/7] " Michael J Gruber
2013-04-23 12:11       ` [PATCHv2 1/7] t4030: demonstrate behavior of show " Michael J Gruber
2013-04-23 15:11         ` Junio C Hamano
2013-04-23 12:11       ` [PATCHv2 2/7] show: obey --textconv for blobs Michael J Gruber
2013-04-23 15:14         ` Junio C Hamano
2013-04-24 10:09           ` Michael J Gruber
2013-04-24 17:30             ` Junio C Hamano
2013-04-23 12:11       ` [PATCHv2 3/7] cat-file: do not die on --textconv without textconv filters Michael J Gruber
2013-04-23 15:15         ` Junio C Hamano
2013-04-23 12:11       ` [PATCHv2 4/7] t7008: demonstrate behavior of grep with textconv Michael J Gruber
2013-04-23 15:16         ` Junio C Hamano
2013-04-24 10:09           ` Michael J Gruber
2013-04-24 17:29             ` Junio C Hamano
2013-04-23 12:11       ` [PATCHv2 5/7] grep: allow to use textconv filters Michael J Gruber
2013-04-23 12:11       ` [PATCHv2 6/7] grep: honor --textconv for the case rev:path Michael J Gruber
2013-04-23 12:11       ` [PATCHv2 7/7] git grep: honor textconv by default Michael J Gruber
2013-04-23 15:20         ` Junio C Hamano
2013-04-24 10:05           ` Michael J Gruber
2013-04-24 17:35             ` Junio C Hamano
2013-04-24 17:57               ` Matthieu Moy
2013-04-24 18:55                 ` Junio C Hamano
2013-04-26 11:59                   ` Michael J Gruber
2013-04-26 13:23                     ` Matthieu Moy
2013-04-29  9:04                       ` Michael J Gruber
2013-04-29 15:04                         ` Junio C Hamano [this message]
2013-05-10 15:08                           ` [PATCHv3 0/7] textconv with grep and show Michael J Gruber
2013-05-10 15:10                             ` [PATCHv3 1/7] t4030: demonstrate behavior of show with textconv Michael J Gruber
2013-05-10 15:10                             ` [PATCHv3 2/7] diff_opt: track whether flags have been set explicitly Michael J Gruber
2013-05-10 15:31                               ` Eric Sunshine
2013-05-10 15:10                             ` [PATCHv3 3/7] show: honor --textconv for blobs Michael J Gruber
2013-05-10 17:02                               ` Junio C Hamano
2013-05-10 17:34                                 ` Jeff King
2013-05-10 18:04                                   ` Junio C Hamano
2013-05-11  0:25                                     ` Jeff King
2013-05-11 19:54                                       ` Junio C Hamano
2013-05-11  8:54                                 ` Michael J Gruber
2013-05-11 10:00                                   ` Michael J Gruber
2013-05-13  5:01                                     ` Junio C Hamano
2013-05-13 11:55                                       ` Jeff King
2013-05-13 14:57                                         ` Michael J Gruber
2013-05-13 15:41                                           ` Junio C Hamano
2013-05-16  3:31                                           ` Jeff King
2013-05-11 17:36                                   ` Junio C Hamano
2013-05-12 12:13                                     ` Michael J Gruber
2013-05-10 15:10                             ` [PATCHv3 4/7] cat-file: do not die on --textconv without textconv filters Michael J Gruber
2013-05-10 15:10                             ` [PATCHv3 5/7] t7008: demonstrate behavior of grep with textconv Michael J Gruber
2013-05-10 15:10                             ` [PATCHv3 6/7] grep: allow to use textconv filters Michael J Gruber
2013-05-10 15:10                             ` [PATCHv3 7/7] grep: honor --textconv for the case rev:path Michael J Gruber
2013-05-10 18:11                               ` Junio C Hamano
2013-05-10 18:31                                 ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=7vy5c1l6nb.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=jeremy.rosen@openwide.fr \
    --cc=peff@peff.net \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.