Code

Merge branch 'js/maint-diff-color-words'
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 Nov 2009 00:41:29 +0000 (16:41 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Nov 2009 00:41:29 +0000 (16:41 -0800)
* js/maint-diff-color-words:
  diff --color-words: bit of clean-up
  diff --color-words -U0: fix the location of hunk headers
  t4034-diff-words: add a test for word diff without context

Conflicts:
diff.c

1  2 
diff.c

diff --cc diff.c
index 3ad1f8c31046ee3dae8a8e9bed6dc9f5a5929b78,8c66e4a0d4e5ab1729f400f7e95c4970952ec202..0d7f5ea4a87d2152638f36b30d6366406d33bfa9
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -686,6 -529,26 +686,14 @@@ static void diff_words_show(struct diff
        diff_words->minus.text.size = diff_words->plus.text.size = 0;
  }
  
 -typedef unsigned long (*sane_truncate_fn)(char *line, unsigned long len);
 -
 -struct emit_callback {
 -      int nparents, color_diff;
 -      unsigned ws_rule;
 -      sane_truncate_fn truncate;
 -      const char **label_path;
 -      struct diff_words_data *diff_words;
 -      int *found_changesp;
 -      FILE *file;
 -};
 -
+ /* In "color-words" mode, show word-diff of words accumulated in the buffer */
+ static void diff_words_flush(struct emit_callback *ecbdata)
+ {
+       if (ecbdata->diff_words->minus.text.size ||
+           ecbdata->diff_words->plus.text.size)
+               diff_words_show(ecbdata->diff_words);
+ }
  static void free_diff_words_data(struct emit_callback *ecbdata)
  {
        if (ecbdata->diff_words) {
@@@ -772,9 -654,16 +776,11 @@@ static void fn_out_consume(void *priv, 
                len = 1;
        }
  
 -      /* This is not really necessary for now because
 -       * this codepath only deals with two-way diffs.
 -       */
 -      for (i = 0; i < len && line[i] == '@'; i++)
 -              ;
 -      if (2 <= i && i < len && line[i] == ' ') {
 +      if (line[0] == '@') {
+               if (ecbdata->diff_words)
+                       diff_words_flush(ecbdata);
 -              ecbdata->nparents = i - 1;
                len = sane_truncate_line(ecbdata, line, len);
 +              find_lno(line, ecbdata);
                emit_line(ecbdata->file,
                          diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO),
                          reset, line, len);