git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/7] diff --color-words: another special diff case

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 31, 2015, 12:37 UTC
Message-ID
<1451565457-18756-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1451565457-18756-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/diff.c b/diff.c
index 8af1df1..1354368 100644
--- a/diff.c
+++ b/diff.c
@@ -1037,6 +1037,16 @@ static void diff_words_show(struct diff_words_data *diff_words)
 		diff_words->minus.text.size = 0;
 		return;
 	}
+	/* special case: only addition */
+	if (!diff_words->minus.text.size) {
+		fputs(line_prefix, diff_words->opt->file);
+		fn_out_diff_words_write_helper(diff_words->opt->file,
+			&style->new, style->newline,
+			diff_words->plus.text.size,
+			diff_words->plus.text.ptr, line_prefix);
+		diff_words->plus.text.size = 0;
+		return;
+	}
 
 	diff_words->current_plus = diff_words->plus.text.ptr;
 	diff_words->last_minus = 0;
-- 
2.3.0.rc1.137.g477eb31
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 4 of 8 in “A failed attempt to integrate diff-highlight to the core”
  1. Nguyễn Thái Ngọc DuyDec 31, 2015
  2. 1/7 diff.c: keep all word diff structs togetherNguyễn Thái Ngọc Duy, Dec 31, 2015
  3. 2/7 diff.c: refactor diff_words_append()Nguyễn Thái Ngọc Duy, Dec 31, 2015
  4. 3/7 diff --color-words: another special diff caseNguyễn Thái Ngọc Duy, Dec 31, 2015
  5. 4/7 diff.c: refactor fn_out_diff_words_write_helper()Nguyễn Thái Ngọc Duy, Dec 31, 2015
  6. 5/7 diff: unified diff with colored words, step 1, unified diff onlyNguyễn Thái Ngọc Duy, Dec 31, 2015
  7. 6/7 diff.c: add new arguments to emit_line_0()Nguyễn Thái Ngọc Duy, Dec 31, 2015
  8. 7/7 diff --highlight-words: actually highlight wordsNguyễn Thái Ngọc Duy, Dec 31, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.