* [PATCH 0/3] preparatory diff improvements for moved color detection @ 2016-09-07 23:36 Stefan Beller 2016-09-07 23:36 ` [PATCH 1/3] diff.c: use diff_options directly Stefan Beller ` (4 more replies) 0 siblings, 5 replies; 9+ messages in thread From: Stefan Beller @ 2016-09-07 23:36 UTC (permalink / raw) To: gitster; +Cc: git, Stefan Beller Motivated by the feedback on the "[PATCHv4] diff.c: emit moved lines with a different color"[1], I started refactoring the fn_out_consume function in diff.c. This lead to a huge amount of tiny patches so far, but nothing to present as an end result. These patches are preparatory for this effort and I want them out such that I do not need to worry about them later. Thanks, Stefan [1] https://public-inbox.org/git/20160906070151.15163-1-stefanbeller@gmail.com/ Stefan Beller (3): diff.c: use diff_options directly diff: omit found pointer from emit_callback diff: remove dead code diff.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) -- 2.10.0.2.g0676c79.dirty ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] diff.c: use diff_options directly 2016-09-07 23:36 [PATCH 0/3] preparatory diff improvements for moved color detection Stefan Beller @ 2016-09-07 23:36 ` Stefan Beller 2016-09-08 5:33 ` Jacob Keller 2016-09-07 23:36 ` [PATCH 1/2] diff: omit found pointer from emit_callback Stefan Beller ` (3 subsequent siblings) 4 siblings, 1 reply; 9+ messages in thread From: Stefan Beller @ 2016-09-07 23:36 UTC (permalink / raw) To: gitster; +Cc: git, Stefan Beller The value of `ecbdata->opt` is accessible via the short variable `o` already, so let's use that instead. Signed-off-by: Stefan Beller <sbeller@google.com> --- diff.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/diff.c b/diff.c index 534c12e..4a6501c 100644 --- a/diff.c +++ b/diff.c @@ -1217,7 +1217,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) const char *line_prefix = diff_line_prefix(o); if (ecbdata->header) { - fprintf(ecbdata->opt->file, "%s", ecbdata->header->buf); + fprintf(o->file, "%s", ecbdata->header->buf); strbuf_reset(ecbdata->header); ecbdata->header = NULL; } @@ -1229,9 +1229,9 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) name_a_tab = strchr(ecbdata->label_path[0], ' ') ? "\t" : ""; name_b_tab = strchr(ecbdata->label_path[1], ' ') ? "\t" : ""; - fprintf(ecbdata->opt->file, "%s%s--- %s%s%s\n", + fprintf(o->file, "%s%s--- %s%s%s\n", line_prefix, meta, ecbdata->label_path[0], reset, name_a_tab); - fprintf(ecbdata->opt->file, "%s%s+++ %s%s%s\n", + fprintf(o->file, "%s%s+++ %s%s%s\n", line_prefix, meta, ecbdata->label_path[1], reset, name_b_tab); ecbdata->label_path[0] = ecbdata->label_path[1] = NULL; } @@ -1249,15 +1249,15 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) find_lno(line, ecbdata); emit_hunk_header(ecbdata, line, len); if (line[len-1] != '\n') - putc('\n', ecbdata->opt->file); + putc('\n', o->file); return; } if (len < 1) { - emit_line(ecbdata->opt, reset, reset, line, len); + emit_line(o, reset, reset, line, len); if (ecbdata->diff_words && ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) - fputs("~\n", ecbdata->opt->file); + fputs("~\n", o->file); return; } @@ -1282,8 +1282,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) } diff_words_flush(ecbdata); if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) { - emit_line(ecbdata->opt, context, reset, line, len); - fputs("~\n", ecbdata->opt->file); + emit_line(o, context, reset, line, len); + fputs("~\n", o->file); } else { /* * Skip the prefix character, if any. With @@ -1294,7 +1294,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) line++; len--; } - emit_line(ecbdata->opt, context, reset, line, len); + emit_line(o, context, reset, line, len); } return; } @@ -1316,8 +1316,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) default: /* incomplete line at the end */ ecbdata->lno_in_preimage++; - emit_line(ecbdata->opt, - diff_get_color(ecbdata->color_diff, DIFF_CONTEXT), + emit_line(o, diff_get_color(ecbdata->color_diff, DIFF_CONTEXT), reset, line, len); break; } -- 2.10.0.2.g0676c79.dirty ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] diff.c: use diff_options directly 2016-09-07 23:36 ` [PATCH 1/3] diff.c: use diff_options directly Stefan Beller @ 2016-09-08 5:33 ` Jacob Keller 0 siblings, 0 replies; 9+ messages in thread From: Jacob Keller @ 2016-09-08 5:33 UTC (permalink / raw) To: Stefan Beller; +Cc: Junio C Hamano, Git mailing list On Wed, Sep 7, 2016 at 4:36 PM, Stefan Beller <sbeller@google.com> wrote: > The value of `ecbdata->opt` is accessible via the short variable `o` > already, so let's use that instead. > > Signed-off-by: Stefan Beller <sbeller@google.com> Seems reasonable. > --- > diff.c | 21 ++++++++++----------- > 1 file changed, 10 insertions(+), 11 deletions(-) > > diff --git a/diff.c b/diff.c > index 534c12e..4a6501c 100644 > --- a/diff.c > +++ b/diff.c > @@ -1217,7 +1217,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > const char *line_prefix = diff_line_prefix(o); > > if (ecbdata->header) { > - fprintf(ecbdata->opt->file, "%s", ecbdata->header->buf); > + fprintf(o->file, "%s", ecbdata->header->buf); > strbuf_reset(ecbdata->header); > ecbdata->header = NULL; > } > @@ -1229,9 +1229,9 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > name_a_tab = strchr(ecbdata->label_path[0], ' ') ? "\t" : ""; > name_b_tab = strchr(ecbdata->label_path[1], ' ') ? "\t" : ""; > > - fprintf(ecbdata->opt->file, "%s%s--- %s%s%s\n", > + fprintf(o->file, "%s%s--- %s%s%s\n", > line_prefix, meta, ecbdata->label_path[0], reset, name_a_tab); > - fprintf(ecbdata->opt->file, "%s%s+++ %s%s%s\n", > + fprintf(o->file, "%s%s+++ %s%s%s\n", > line_prefix, meta, ecbdata->label_path[1], reset, name_b_tab); > ecbdata->label_path[0] = ecbdata->label_path[1] = NULL; > } > @@ -1249,15 +1249,15 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > find_lno(line, ecbdata); > emit_hunk_header(ecbdata, line, len); > if (line[len-1] != '\n') > - putc('\n', ecbdata->opt->file); > + putc('\n', o->file); > return; > } > > if (len < 1) { > - emit_line(ecbdata->opt, reset, reset, line, len); > + emit_line(o, reset, reset, line, len); > if (ecbdata->diff_words > && ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) > - fputs("~\n", ecbdata->opt->file); > + fputs("~\n", o->file); > return; > } > > @@ -1282,8 +1282,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > } > diff_words_flush(ecbdata); > if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) { > - emit_line(ecbdata->opt, context, reset, line, len); > - fputs("~\n", ecbdata->opt->file); > + emit_line(o, context, reset, line, len); > + fputs("~\n", o->file); > } else { > /* > * Skip the prefix character, if any. With > @@ -1294,7 +1294,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > line++; > len--; > } > - emit_line(ecbdata->opt, context, reset, line, len); > + emit_line(o, context, reset, line, len); > } > return; > } > @@ -1316,8 +1316,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > default: > /* incomplete line at the end */ > ecbdata->lno_in_preimage++; > - emit_line(ecbdata->opt, > - diff_get_color(ecbdata->color_diff, DIFF_CONTEXT), > + emit_line(o, diff_get_color(ecbdata->color_diff, DIFF_CONTEXT), > reset, line, len); > break; > } > -- > 2.10.0.2.g0676c79.dirty > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] diff: omit found pointer from emit_callback 2016-09-07 23:36 [PATCH 0/3] preparatory diff improvements for moved color detection Stefan Beller 2016-09-07 23:36 ` [PATCH 1/3] diff.c: use diff_options directly Stefan Beller @ 2016-09-07 23:36 ` Stefan Beller 2016-09-07 23:36 ` [PATCH 2/3] " Stefan Beller ` (2 subsequent siblings) 4 siblings, 0 replies; 9+ messages in thread From: Stefan Beller @ 2016-09-07 23:36 UTC (permalink / raw) To: gitster; +Cc: git, Stefan Beller We keep the actual data in the diff options, which are just as accessible. Remove the pointer stored in struct emit_callback for readability. Signed-off-by: Stefan Beller <sbeller@google.com> --- diff.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/diff.c b/diff.c index 4a6501c..79ad91d 100644 --- a/diff.c +++ b/diff.c @@ -354,7 +354,6 @@ struct emit_callback { const char **label_path; struct diff_words_data *diff_words; struct diff_options *opt; - int *found_changesp; struct strbuf *header; }; @@ -722,7 +721,6 @@ static void emit_rewrite_diff(const char *name_a, memset(&ecbdata, 0, sizeof(ecbdata)); ecbdata.color_diff = want_color(o->use_color); - ecbdata.found_changesp = &o->found_changes; ecbdata.ws_rule = whitespace_rule(name_b); ecbdata.opt = o; if (ecbdata.ws_rule & WS_BLANK_AT_EOF) { @@ -1215,13 +1213,13 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET); struct diff_options *o = ecbdata->opt; const char *line_prefix = diff_line_prefix(o); + o->found_changes = 1; if (ecbdata->header) { fprintf(o->file, "%s", ecbdata->header->buf); strbuf_reset(ecbdata->header); ecbdata->header = NULL; } - *(ecbdata->found_changesp) = 1; if (ecbdata->label_path[0]) { const char *name_a_tab, *name_b_tab; @@ -2437,7 +2435,6 @@ static void builtin_diff(const char *name_a, memset(&ecbdata, 0, sizeof(ecbdata)); ecbdata.label_path = lbl; ecbdata.color_diff = want_color(o->use_color); - ecbdata.found_changesp = &o->found_changes; ecbdata.ws_rule = whitespace_rule(name_b); if (ecbdata.ws_rule & WS_BLANK_AT_EOF) check_blank_at_eof(&mf1, &mf2, &ecbdata); -- 2.10.0.2.g0676c79.dirty ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] diff: omit found pointer from emit_callback 2016-09-07 23:36 [PATCH 0/3] preparatory diff improvements for moved color detection Stefan Beller 2016-09-07 23:36 ` [PATCH 1/3] diff.c: use diff_options directly Stefan Beller 2016-09-07 23:36 ` [PATCH 1/2] diff: omit found pointer from emit_callback Stefan Beller @ 2016-09-07 23:36 ` Stefan Beller 2016-09-08 20:53 ` Junio C Hamano 2016-09-07 23:36 ` [PATCH 2/2] diff: remove dead code Stefan Beller 2016-09-07 23:36 ` [PATCH 3/3] " Stefan Beller 4 siblings, 1 reply; 9+ messages in thread From: Stefan Beller @ 2016-09-07 23:36 UTC (permalink / raw) To: gitster; +Cc: git, Stefan Beller We keep the actual data in the diff options, which are just as accessible. Remove the pointer stored in struct emit_callback for readability. Signed-off-by: Stefan Beller <sbeller@google.com> --- diff.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/diff.c b/diff.c index 4a6501c..79ad91d 100644 --- a/diff.c +++ b/diff.c @@ -354,7 +354,6 @@ struct emit_callback { const char **label_path; struct diff_words_data *diff_words; struct diff_options *opt; - int *found_changesp; struct strbuf *header; }; @@ -722,7 +721,6 @@ static void emit_rewrite_diff(const char *name_a, memset(&ecbdata, 0, sizeof(ecbdata)); ecbdata.color_diff = want_color(o->use_color); - ecbdata.found_changesp = &o->found_changes; ecbdata.ws_rule = whitespace_rule(name_b); ecbdata.opt = o; if (ecbdata.ws_rule & WS_BLANK_AT_EOF) { @@ -1215,13 +1213,13 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET); struct diff_options *o = ecbdata->opt; const char *line_prefix = diff_line_prefix(o); + o->found_changes = 1; if (ecbdata->header) { fprintf(o->file, "%s", ecbdata->header->buf); strbuf_reset(ecbdata->header); ecbdata->header = NULL; } - *(ecbdata->found_changesp) = 1; if (ecbdata->label_path[0]) { const char *name_a_tab, *name_b_tab; @@ -2437,7 +2435,6 @@ static void builtin_diff(const char *name_a, memset(&ecbdata, 0, sizeof(ecbdata)); ecbdata.label_path = lbl; ecbdata.color_diff = want_color(o->use_color); - ecbdata.found_changesp = &o->found_changes; ecbdata.ws_rule = whitespace_rule(name_b); if (ecbdata.ws_rule & WS_BLANK_AT_EOF) check_blank_at_eof(&mf1, &mf2, &ecbdata); -- 2.10.0.2.g0676c79.dirty ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] diff: omit found pointer from emit_callback 2016-09-07 23:36 ` [PATCH 2/3] " Stefan Beller @ 2016-09-08 20:53 ` Junio C Hamano 0 siblings, 0 replies; 9+ messages in thread From: Junio C Hamano @ 2016-09-08 20:53 UTC (permalink / raw) To: Stefan Beller; +Cc: git Stefan Beller <sbeller@google.com> writes: > diff --git a/diff.c b/diff.c > index 4a6501c..79ad91d 100644 > --- a/diff.c > +++ b/diff.c > @@ -354,7 +354,6 @@ struct emit_callback { > const char **label_path; > struct diff_words_data *diff_words; > struct diff_options *opt; > - int *found_changesp; > struct strbuf *header; > }; I briefly wondered if we have some callsites that do not want o->found_changes to be modified (hence pointing this field at elsewhere), but the fact that you can _remove_ this field means that there is no such use case, which is good. > @@ -722,7 +721,6 @@ static void emit_rewrite_diff(const char *name_a, > > memset(&ecbdata, 0, sizeof(ecbdata)); > ecbdata.color_diff = want_color(o->use_color); > - ecbdata.found_changesp = &o->found_changes; > ecbdata.ws_rule = whitespace_rule(name_b); > ecbdata.opt = o; > if (ecbdata.ws_rule & WS_BLANK_AT_EOF) { > @@ -1215,13 +1213,13 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET); > struct diff_options *o = ecbdata->opt; > const char *line_prefix = diff_line_prefix(o); > + o->found_changes = 1; > > if (ecbdata->header) { > fprintf(o->file, "%s", ecbdata->header->buf); > strbuf_reset(ecbdata->header); > ecbdata->header = NULL; > } > - *(ecbdata->found_changesp) = 1; Is there a good reason to move the assignment up? "The fact that this function was called even once means we found some change" is probably a good argument, but then I'd prefer to have a blank before it to separate it (the first statement) from the block of decls. No need to resend. Thanks. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] diff: remove dead code 2016-09-07 23:36 [PATCH 0/3] preparatory diff improvements for moved color detection Stefan Beller ` (2 preceding siblings ...) 2016-09-07 23:36 ` [PATCH 2/3] " Stefan Beller @ 2016-09-07 23:36 ` Stefan Beller 2016-09-07 23:36 ` [PATCH 3/3] " Stefan Beller 4 siblings, 0 replies; 9+ messages in thread From: Stefan Beller @ 2016-09-07 23:36 UTC (permalink / raw) To: gitster; +Cc: git, Stefan Beller When `len < 1`, len has to be 0 or negative, emit_line will then remove the first character and by then `len` would be negative. As this doesn't happen, it is safe to assume it is dead code. This continues to simplify the code, which was started in b8d9c1a66b (2009-09-03, diff.c: the builtin_diff() deals with only two-file comparison). Signed-off-by: Stefan Beller <sbeller@google.com> --- diff.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/diff.c b/diff.c index 79ad91d..c143019 100644 --- a/diff.c +++ b/diff.c @@ -1251,14 +1251,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) return; } - if (len < 1) { - emit_line(o, reset, reset, line, len); - if (ecbdata->diff_words - && ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) - fputs("~\n", o->file); - return; - } - if (ecbdata->diff_words) { if (line[0] == '-') { diff_words_append(line, len, -- 2.10.0.2.g0676c79.dirty ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] diff: remove dead code 2016-09-07 23:36 [PATCH 0/3] preparatory diff improvements for moved color detection Stefan Beller ` (3 preceding siblings ...) 2016-09-07 23:36 ` [PATCH 2/2] diff: remove dead code Stefan Beller @ 2016-09-07 23:36 ` Stefan Beller 2016-09-08 21:07 ` Junio C Hamano 4 siblings, 1 reply; 9+ messages in thread From: Stefan Beller @ 2016-09-07 23:36 UTC (permalink / raw) To: gitster; +Cc: git, Stefan Beller When `len < 1`, len has to be 0 or negative, emit_line will then remove the first character and by then `len` would be negative. As this doesn't happen, it is safe to assume it is dead code. This continues to simplify the code, which was started in b8d9c1a66b (2009-09-03, diff.c: the builtin_diff() deals with only two-file comparison). Signed-off-by: Stefan Beller <sbeller@google.com> --- diff.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/diff.c b/diff.c index 79ad91d..c143019 100644 --- a/diff.c +++ b/diff.c @@ -1251,14 +1251,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) return; } - if (len < 1) { - emit_line(o, reset, reset, line, len); - if (ecbdata->diff_words - && ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) - fputs("~\n", o->file); - return; - } - if (ecbdata->diff_words) { if (line[0] == '-') { diff_words_append(line, len, -- 2.10.0.2.g0676c79.dirty ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] diff: remove dead code 2016-09-07 23:36 ` [PATCH 3/3] " Stefan Beller @ 2016-09-08 21:07 ` Junio C Hamano 0 siblings, 0 replies; 9+ messages in thread From: Junio C Hamano @ 2016-09-08 21:07 UTC (permalink / raw) To: Stefan Beller; +Cc: git Stefan Beller <sbeller@google.com> writes: > When `len < 1`, len has to be 0 or negative, emit_line will then remove the > first character and by then `len` would be negative. As this doesn't > happen, it is safe to assume it is dead code. > > This continues to simplify the code, which was started in b8d9c1a66b > (2009-09-03, diff.c: the builtin_diff() deals with only two-file > comparison). We look at line[0] to see if it is '@' before this check, which would have been wrong if "len < 1" were ever true. > > Signed-off-by: Stefan Beller <sbeller@google.com> > --- > diff.c | 8 -------- > 1 file changed, 8 deletions(-) > > diff --git a/diff.c b/diff.c > index 79ad91d..c143019 100644 > --- a/diff.c > +++ b/diff.c > @@ -1251,14 +1251,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) > return; > } > > - if (len < 1) { > - emit_line(o, reset, reset, line, len); > - if (ecbdata->diff_words > - && ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) > - fputs("~\n", o->file); > - return; > - } > - > if (ecbdata->diff_words) { > if (line[0] == '-') { > diff_words_append(line, len, ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-09-08 21:07 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-09-07 23:36 [PATCH 0/3] preparatory diff improvements for moved color detection Stefan Beller 2016-09-07 23:36 ` [PATCH 1/3] diff.c: use diff_options directly Stefan Beller 2016-09-08 5:33 ` Jacob Keller 2016-09-07 23:36 ` [PATCH 1/2] diff: omit found pointer from emit_callback Stefan Beller 2016-09-07 23:36 ` [PATCH 2/3] " Stefan Beller 2016-09-08 20:53 ` Junio C Hamano 2016-09-07 23:36 ` [PATCH 2/2] diff: remove dead code Stefan Beller 2016-09-07 23:36 ` [PATCH 3/3] " Stefan Beller 2016-09-08 21:07 ` Junio C Hamano
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.