* [PATCH] diff.c: pass sign_index to emit_line_ws_markup
@ 2018-10-10 23:24 Stefan Beller
2018-10-12 9:37 ` Johannes Schindelin
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Beller @ 2018-10-10 23:24 UTC (permalink / raw)
To: git; +Cc: Stefan Beller
Instead of passing the sign directly to emit_line_ws_markup, pass only the
index to lookup the sign in diff_options->output_indicators.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
I still have this patch laying around, it simplifies the diff code
a tiny bit.
Stefan
diff.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/diff.c b/diff.c
index f0c7557b40..9e895f2191 100644
--- a/diff.c
+++ b/diff.c
@@ -1202,10 +1202,11 @@ static void dim_moved_lines(struct diff_options *o)
static void emit_line_ws_markup(struct diff_options *o,
const char *set_sign, const char *set,
const char *reset,
- char sign, const char *line, int len,
+ int sign_index, const char *line, int len,
unsigned ws_rule, int blank_at_eof)
{
const char *ws = NULL;
+ int sign = o->output_indicators[sign_index];
if (o->ws_error_highlight & ws_rule) {
ws = diff_get_color_opt(o, DIFF_WHITESPACE);
@@ -1285,8 +1286,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
set = diff_get_color_opt(o, DIFF_FILE_OLD);
}
emit_line_ws_markup(o, set_sign, set, reset,
- o->output_indicators[OUTPUT_INDICATOR_CONTEXT],
- line, len,
+ OUTPUT_INDICATOR_CONTEXT, line, len,
flags & (DIFF_SYMBOL_CONTENT_WS_MASK), 0);
break;
case DIFF_SYMBOL_PLUS:
@@ -1330,8 +1330,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
}
emit_line_ws_markup(o, set_sign, set, reset,
- o->output_indicators[OUTPUT_INDICATOR_NEW],
- line, len,
+ OUTPUT_INDICATOR_NEW, line, len,
flags & DIFF_SYMBOL_CONTENT_WS_MASK,
flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
break;
@@ -1375,8 +1374,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
}
emit_line_ws_markup(o, set_sign, set, reset,
- o->output_indicators[OUTPUT_INDICATOR_OLD],
- line, len,
+ OUTPUT_INDICATOR_OLD, line, len,
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
break;
case DIFF_SYMBOL_WORDS_PORCELAIN:
--
2.19.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] diff.c: pass sign_index to emit_line_ws_markup
2018-10-10 23:24 [PATCH] diff.c: pass sign_index to emit_line_ws_markup Stefan Beller
@ 2018-10-12 9:37 ` Johannes Schindelin
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2018-10-12 9:37 UTC (permalink / raw)
To: Stefan Beller; +Cc: git
Hi Stefan,
On Wed, 10 Oct 2018, Stefan Beller wrote:
> Instead of passing the sign directly to emit_line_ws_markup, pass only the
> index to lookup the sign in diff_options->output_indicators.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> I still have this patch laying around, it simplifies the diff code
> a tiny bit.
And I still like it (obviously, was my idea :-))
Thanks,
Dscho
>
> Stefan
>
> diff.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index f0c7557b40..9e895f2191 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -1202,10 +1202,11 @@ static void dim_moved_lines(struct diff_options *o)
> static void emit_line_ws_markup(struct diff_options *o,
> const char *set_sign, const char *set,
> const char *reset,
> - char sign, const char *line, int len,
> + int sign_index, const char *line, int len,
> unsigned ws_rule, int blank_at_eof)
> {
> const char *ws = NULL;
> + int sign = o->output_indicators[sign_index];
>
> if (o->ws_error_highlight & ws_rule) {
> ws = diff_get_color_opt(o, DIFF_WHITESPACE);
> @@ -1285,8 +1286,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
> set = diff_get_color_opt(o, DIFF_FILE_OLD);
> }
> emit_line_ws_markup(o, set_sign, set, reset,
> - o->output_indicators[OUTPUT_INDICATOR_CONTEXT],
> - line, len,
> + OUTPUT_INDICATOR_CONTEXT, line, len,
> flags & (DIFF_SYMBOL_CONTENT_WS_MASK), 0);
> break;
> case DIFF_SYMBOL_PLUS:
> @@ -1330,8 +1330,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
> flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
> }
> emit_line_ws_markup(o, set_sign, set, reset,
> - o->output_indicators[OUTPUT_INDICATOR_NEW],
> - line, len,
> + OUTPUT_INDICATOR_NEW, line, len,
> flags & DIFF_SYMBOL_CONTENT_WS_MASK,
> flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
> break;
> @@ -1375,8 +1374,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
> set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
> }
> emit_line_ws_markup(o, set_sign, set, reset,
> - o->output_indicators[OUTPUT_INDICATOR_OLD],
> - line, len,
> + OUTPUT_INDICATOR_OLD, line, len,
> flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
> break;
> case DIFF_SYMBOL_WORDS_PORCELAIN:
> --
> 2.19.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] diff.c: add --output-indicator-{new, old, context}
@ 2018-08-21 16:13 Johannes Schindelin
2018-08-22 22:25 ` [PATCH] diff.c: pass sign_index to emit_line_ws_markup Stefan Beller
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2018-08-21 16:13 UTC (permalink / raw)
To: Stefan Beller; +Cc: git, Junio C Hamano
Hi Stefan,
On Mon, 20 Aug 2018, Stefan Beller wrote:
> On Mon, Aug 20, 2018 at 12:31 PM Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> >
> > On Fri, 17 Aug 2018, Stefan Beller wrote:
> >
> > > This will prove useful in range-diff in a later patch as we will be able
> > > to differentiate between adding a new file (that line is starting with
> > > +++ and then the file name) and regular new lines.
> > >
> > > It could also be useful for experimentation in new patch formats, i.e.
> > > we could teach git to emit moved lines with lines other than +/-.
> >
> > Thanks.
> >
> > > diff --git a/diff.c b/diff.c
> > > index c5c7739ce34..03486c35b75 100644
> > > --- a/diff.c
> > > +++ b/diff.c
> > > @@ -1281,7 +1281,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
> > > else if (c == '-')
> > > set = diff_get_color_opt(o, DIFF_FILE_OLD);
> > > }
> > > - emit_line_ws_markup(o, set_sign, set, reset, ' ', line, len,
> > ^
> > Here we already pass `o`... so...
> >
> > > + emit_line_ws_markup(o, set_sign, set, reset,
> > > + o->output_indicators[OUTPUT_INDICATOR_CONTEXT],
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > ... here, we could simply pass `OUTPUT_INDICATOR_CONTEXT` and let the
> > callee look it up in`o->output_indicators[]`...
> >
> > I read all three patches and did not see a reason why we could not
> > simplify the code that way.
> >
> > Other than that: great!
>
> Thanks!
>
> I considered it, but was put off by the (small) effort of yet another
> diff refactoring.
>
> I'll include it in a resend if a resend is needed, otherwise
> I would suggest to make it a patch on top?
Sounds good!
Dscho
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] diff.c: pass sign_index to emit_line_ws_markup
2018-08-21 16:13 [PATCH 1/3] diff.c: add --output-indicator-{new, old, context} Johannes Schindelin
@ 2018-08-22 22:25 ` Stefan Beller
2018-08-23 14:26 ` Johannes Schindelin
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Beller @ 2018-08-22 22:25 UTC (permalink / raw)
To: johannes.schindelin; +Cc: git, gitster, sbeller
Instead of passing the sign directly to emit_line_ws_markup, pass only the
index to lookup the sign in diff_options->output_indicators.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
diff.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
So something like this on top of sb/range-diff-colors ?
If a resend is needed I'll squash this in (or carry it as a cleanup patch early
in the series), otherwise we could put this on top.
Thanks,
Stefan
diff --git a/diff.c b/diff.c
index 03486c35b75..17e33d506a1 100644
--- a/diff.c
+++ b/diff.c
@@ -1199,10 +1199,11 @@ static void dim_moved_lines(struct diff_options *o)
static void emit_line_ws_markup(struct diff_options *o,
const char *set_sign, const char *set,
const char *reset,
- char sign, const char *line, int len,
+ int sign_index, const char *line, int len,
unsigned ws_rule, int blank_at_eof)
{
const char *ws = NULL;
+ int sign = o->output_indicators[sign_index];
if (o->ws_error_highlight & ws_rule) {
ws = diff_get_color_opt(o, DIFF_WHITESPACE);
@@ -1282,8 +1283,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
set = diff_get_color_opt(o, DIFF_FILE_OLD);
}
emit_line_ws_markup(o, set_sign, set, reset,
- o->output_indicators[OUTPUT_INDICATOR_CONTEXT],
- line, len,
+ OUTPUT_INDICATOR_CONTEXT, line, len,
flags & (DIFF_SYMBOL_CONTENT_WS_MASK), 0);
break;
case DIFF_SYMBOL_PLUS:
@@ -1327,8 +1327,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
}
emit_line_ws_markup(o, set_sign, set, reset,
- o->output_indicators[OUTPUT_INDICATOR_NEW],
- line, len,
+ OUTPUT_INDICATOR_NEW, line, len,
flags & DIFF_SYMBOL_CONTENT_WS_MASK,
flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
break;
@@ -1372,8 +1371,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
}
emit_line_ws_markup(o, set_sign, set, reset,
- o->output_indicators[OUTPUT_INDICATOR_OLD],
- line, len,
+ OUTPUT_INDICATOR_OLD, line, len,
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
break;
case DIFF_SYMBOL_WORDS_PORCELAIN:
--
2.18.0.265.g16de1b435c9.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] diff.c: pass sign_index to emit_line_ws_markup
2018-08-22 22:25 ` [PATCH] diff.c: pass sign_index to emit_line_ws_markup Stefan Beller
@ 2018-08-23 14:26 ` Johannes Schindelin
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2018-08-23 14:26 UTC (permalink / raw)
To: Stefan Beller; +Cc: git, gitster
Hi Stefan,
On Wed, 22 Aug 2018, Stefan Beller wrote:
> Instead of passing the sign directly to emit_line_ws_markup, pass only the
> index to lookup the sign in diff_options->output_indicators.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
Looks good to me!
> ---
> diff.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> So something like this on top of sb/range-diff-colors ? If a resend is
> needed I'll squash this in (or carry it as a cleanup patch early in the
> series), otherwise we could put this on top.
I'd leave this as a separate commit.
Ciao,
Dscho
>
> Thanks,
> Stefan
>
>
> diff --git a/diff.c b/diff.c
> index 03486c35b75..17e33d506a1 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -1199,10 +1199,11 @@ static void dim_moved_lines(struct diff_options *o)
> static void emit_line_ws_markup(struct diff_options *o,
> const char *set_sign, const char *set,
> const char *reset,
> - char sign, const char *line, int len,
> + int sign_index, const char *line, int len,
> unsigned ws_rule, int blank_at_eof)
> {
> const char *ws = NULL;
> + int sign = o->output_indicators[sign_index];
>
> if (o->ws_error_highlight & ws_rule) {
> ws = diff_get_color_opt(o, DIFF_WHITESPACE);
> @@ -1282,8 +1283,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
> set = diff_get_color_opt(o, DIFF_FILE_OLD);
> }
> emit_line_ws_markup(o, set_sign, set, reset,
> - o->output_indicators[OUTPUT_INDICATOR_CONTEXT],
> - line, len,
> + OUTPUT_INDICATOR_CONTEXT, line, len,
> flags & (DIFF_SYMBOL_CONTENT_WS_MASK), 0);
> break;
> case DIFF_SYMBOL_PLUS:
> @@ -1327,8 +1327,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
> flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
> }
> emit_line_ws_markup(o, set_sign, set, reset,
> - o->output_indicators[OUTPUT_INDICATOR_NEW],
> - line, len,
> + OUTPUT_INDICATOR_NEW, line, len,
> flags & DIFF_SYMBOL_CONTENT_WS_MASK,
> flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
> break;
> @@ -1372,8 +1371,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
> set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
> }
> emit_line_ws_markup(o, set_sign, set, reset,
> - o->output_indicators[OUTPUT_INDICATOR_OLD],
> - line, len,
> + OUTPUT_INDICATOR_OLD, line, len,
> flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
> break;
> case DIFF_SYMBOL_WORDS_PORCELAIN:
> --
> 2.18.0.265.g16de1b435c9.dirty
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-10-12 9:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 23:24 [PATCH] diff.c: pass sign_index to emit_line_ws_markup Stefan Beller
2018-10-12 9:37 ` Johannes Schindelin
-- strict thread matches above, loose matches on Subject: below --
2018-08-21 16:13 [PATCH 1/3] diff.c: add --output-indicator-{new, old, context} Johannes Schindelin
2018-08-22 22:25 ` [PATCH] diff.c: pass sign_index to emit_line_ws_markup Stefan Beller
2018-08-23 14:26 ` Johannes Schindelin
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 NNTP newsgroup(s).