From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/7] diff.c: refactor diff_words_append()
Date: Thu, 31 Dec 2015 19:37:32 +0700 [thread overview]
Message-ID: <1451565457-18756-3-git-send-email-pclouds@gmail.com> (raw)
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 | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/diff.c b/diff.c
index dfbed41..8af1df1 100644
--- a/diff.c
+++ b/diff.c
@@ -788,9 +788,17 @@ struct diff_words_data {
struct diff_words_style *style;
};
-static void diff_words_append(char *line, unsigned long len,
- struct diff_words_buffer *buffer)
+static void diff_words_append(struct diff_words_data *diff_words,
+ char *line, unsigned long len)
{
+ struct diff_words_buffer *buffer;
+
+ if (line[0] == '-')
+ buffer = &diff_words->minus;
+ else {
+ assert(line[0] == '+');
+ buffer = &diff_words->plus;
+ }
ALLOC_GROW(buffer->text.ptr, buffer->text.size + len, buffer->alloc);
line++;
len--;
@@ -1252,13 +1260,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
}
if (ecbdata->diff_words) {
- if (line[0] == '-') {
- diff_words_append(line, len,
- &ecbdata->diff_words->minus);
- return;
- } else if (line[0] == '+') {
- diff_words_append(line, len,
- &ecbdata->diff_words->plus);
+ if (line[0] == '-' || line[0] == '+') {
+ diff_words_append(ecbdata->diff_words, line, len);
return;
} else if (starts_with(line, "\\ ")) {
/*
--
2.3.0.rc1.137.g477eb31
next prev parent reply other threads:[~2015-12-31 12:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-31 12:37 A failed attempt to integrate diff-highlight to the core Nguyễn Thái Ngọc Duy
2015-12-31 12:37 ` [PATCH 1/7] diff.c: keep all word diff structs together Nguyễn Thái Ngọc Duy
2015-12-31 12:37 ` Nguyễn Thái Ngọc Duy [this message]
2015-12-31 12:37 ` [PATCH 3/7] diff --color-words: another special diff case Nguyễn Thái Ngọc Duy
2015-12-31 12:37 ` [PATCH 4/7] diff.c: refactor fn_out_diff_words_write_helper() Nguyễn Thái Ngọc Duy
2015-12-31 12:37 ` [PATCH 5/7] diff: unified diff with colored words, step 1, unified diff only Nguyễn Thái Ngọc Duy
2015-12-31 12:37 ` [PATCH 6/7] diff.c: add new arguments to emit_line_0() Nguyễn Thái Ngọc Duy
2015-12-31 12:37 ` [PATCH 7/7] diff --highlight-words: actually highlight words Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1451565457-18756-3-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).