MCPcopy Create free account
hub / github.com/git/git / fn_out_diff_words_write_helper

Function fn_out_diff_words_write_helper

diff.c:2009–2053  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2007};
2008
2009static int fn_out_diff_words_write_helper(struct diff_options *o,
2010 struct diff_words_style_elem *st_el,
2011 const char *newline,
2012 size_t count, const char *buf)
2013{
2014 int print = 0;
2015 struct strbuf sb = STRBUF_INIT;
2016
2017 while (count) {
2018 const char *p = memchr(buf, '\n', count);
2019 if (print)
2020 strbuf_addstr(&sb, diff_line_prefix(o));
2021
2022 if (p != buf) {
2023 const char *reset = st_el->color && *st_el->color ?
2024 GIT_COLOR_RESET : NULL;
2025 if (st_el->color && *st_el->color)
2026 strbuf_addstr(&sb, st_el->color);
2027 strbuf_addstr(&sb, st_el->prefix);
2028 strbuf_add(&sb, buf, p ? p - buf : count);
2029 strbuf_addstr(&sb, st_el->suffix);
2030 if (reset)
2031 strbuf_addstr(&sb, reset);
2032 }
2033 if (!p)
2034 goto out;
2035
2036 strbuf_addstr(&sb, newline);
2037 count -= p + 1 - buf;
2038 buf = p + 1;
2039 print = 1;
2040 if (count) {
2041 emit_diff_symbol(o, DIFF_SYMBOL_WORD_DIFF,
2042 sb.buf, sb.len, 0);
2043 strbuf_reset(&sb);
2044 }
2045 }
2046
2047out:
2048 if (sb.len)
2049 emit_diff_symbol(o, DIFF_SYMBOL_WORD_DIFF,
2050 sb.buf, sb.len, 0);
2051 strbuf_release(&sb);
2052 return 0;
2053}
2054
2055/*
2056 * '--color-words' algorithm can be described as:

Callers 2

fn_out_diff_words_auxFunction · 0.85
diff_words_showFunction · 0.85

Calls 5

strbuf_addstrFunction · 0.85
diff_line_prefixFunction · 0.85
strbuf_addFunction · 0.85
emit_diff_symbolFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected