@matheusbsbs / matheus-bagliano / commits / b8d9c1a66b
Fork 0

diff.c: the builtin_diff() deals with only two-file comparison

The combined diff is implemented in combine_diff() and fn_out_consume() codepath never has to deal with anything but two-file comparision. Drop nparents from the emit_callback structure and simplify the code. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 3, 2009 at 23:59 UTC b8d9c1a66b99ad3ca8069add010dafdd1bc6cab8
1 file changed +9 -23
diff.c
+9 -23
@@ -489,7 +489,7 @@ typedef unsigned long (*sane_truncate_fn)(char *line, unsigned long len);
489
490 struct emit_callback {
491 struct xdiff_emit_state xm;
492 - int nparents, color_diff;
492 + int color_diff;
493 unsigned ws_rule;
494 sane_truncate_fn truncate;
495 const char **label_path;
@@ -549,9 +549,8 @@ static void emit_add_line(const char *reset, struct emit_callback *ecbdata, cons
549 emit_line(ecbdata->file, set, reset, line, len);
550 else {
551 /* Emit just the prefix, then the rest. */
552 - emit_line(ecbdata->file, set, reset, line, ecbdata->nparents);
553 - ws_check_emit(line + ecbdata->nparents,
554 - len - ecbdata->nparents, ecbdata->ws_rule,
552 + emit_line(ecbdata->file, set, reset, line, 1);
553 + ws_check_emit(line + 1, len - 1, ecbdata->ws_rule,
554 ecbdata->file, set, reset, ws);
555 }
556 }
@@ -576,7 +575,6 @@ static unsigned long sane_truncate_line(struct emit_callback *ecb, char *line, u
575
576 static void fn_out_consume(void *priv, char *line, unsigned long len)
577 {
579 - int i;
578 int color;
579 struct emit_callback *ecbdata = priv;
580 const char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
@@ -598,13 +596,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
596 ecbdata->label_path[0] = ecbdata->label_path[1] = NULL;
597 }
598
601 - /* This is not really necessary for now because
602 - * this codepath only deals with two-way diffs.
603 - */
604 - for (i = 0; i < len && line[i] == '@'; i++)
605 - ;
606 - if (2 <= i && i < len && line[i] == ' ') {
607 - ecbdata->nparents = i - 1;
599 + if (line[0] == '@') {
600 len = sane_truncate_line(ecbdata, line, len);
601 emit_line(ecbdata->file,
602 diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO),
@@ -614,15 +606,12 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
606 return;
607 }
608
617 - if (len < ecbdata->nparents) {
609 + if (len < 1) {
610 emit_line(ecbdata->file, reset, reset, line, len);
611 return;
612 }
613
614 color = DIFF_PLAIN;
623 - if (ecbdata->diff_words && ecbdata->nparents != 1)
624 - /* fall back to normal diff */
625 - free_diff_words_data(ecbdata);
615 if (ecbdata->diff_words) {
616 if (line[0] == '-') {
617 diff_words_append(line, len,
@@ -641,13 +630,10 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
630 emit_line(ecbdata->file, plain, reset, line, len);
631 return;
632 }
644 - for (i = 0; i < ecbdata->nparents && len; i++) {
645 - if (line[i] == '-')
646 - color = DIFF_FILE_OLD;
647 - else if (line[i] == '+')
648 - color = DIFF_FILE_NEW;
649 - }
650 -
633 + if (line[0] == '-')
634 + color = DIFF_FILE_OLD;
635 + else if (line[0] == '+')
636 + color = DIFF_FILE_NEW;
637 if (color != DIFF_FILE_NEW) {
638 emit_line(ecbdata->file,
639 diff_get_color(ecbdata->color_diff, color),