Previously --color-words only allow spaces as words boundary. However, just space is not enough. For example, when i rename a function from foo to bar, following example doesn't show as expected when using --color-words. ------------------ - if (foo(arg)) + if (bar(arg)) ------------------ It shows as "if <r>(foo(arg))</r><g>(foo(arg))</g>". Actually, it's the best to show as "if (<r>foo</r><g>bar</g>(arg))". Here "r" and "g" represent "red" and "green" separately. This patch introduces a configuration diff.wordsboundary to make --color-words treat both spaces and characters in diff.wordsboundary as boundary characters. If we set diff.wordsboundary to "()", the example above will show as "if (<r>foo(</r><g>bar(</g>arg))". It's much better, athough not the best, Signed-off-by: Ping Yin <pkufranky@xxxxxxxxx> --- diff.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 3632b55..2c37bb6 100644 --- a/diff.c +++ b/diff.c @@ -23,6 +23,7 @@ static int diff_rename_limit_default = 100; int diff_use_color_default = -1; static const char *external_diff_cmd_cfg; int diff_auto_refresh_index = 1; +static const char *diff_words_boundary = ""; static char diff_colors[][COLOR_MAXLEN] = { "\033[m", /* reset */ @@ -159,6 +160,10 @@ int git_diff_ui_config(const char *var, const char *value) external_diff_cmd_cfg = xstrdup(value); return 0; } + if (!strcmp(var, "diff.wordsboundary")) { + diff_words_boundary = value ? xstrdup(value) : ""; + return 0; + } if (!prefixcmp(var, "diff.")) { const char *ep = strrchr(var, '.'); @@ -434,6 +439,11 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len) } } +static int iswordsboundary(char c) +{ + return isspace(c) || !!strchr(diff_words_boundary, c); +} + /* this executes the word diff on the accumulated buffers */ static void diff_words_show(struct diff_words_data *diff_words) { @@ -448,7 +458,7 @@ static void diff_words_show(struct diff_words_data *diff_words) minus.ptr = xmalloc(minus.size); memcpy(minus.ptr, diff_words->minus.text.ptr, minus.size); for (i = 0; i < minus.size; i++) - if (isspace(minus.ptr[i])) + if (iswordsboundary(minus.ptr[i])) minus.ptr[i] = '\n'; diff_words->minus.current = 0; @@ -456,7 +466,7 @@ static void diff_words_show(struct diff_words_data *diff_words) plus.ptr = xmalloc(plus.size); memcpy(plus.ptr, diff_words->plus.text.ptr, plus.size); for (i = 0; i < plus.size; i++) - if (isspace(plus.ptr[i])) + if (iswordsboundary(plus.ptr[i])) plus.ptr[i] = '\n'; diff_words->plus.current = 0; -- 1.5.5.1.116.ge4b9c.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html