From: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
To: Jonas Fonseca <jonas.fonseca@gmail.com>, git@vger.kernel.org
Cc: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
Subject: [tig] [PATCH 1/3] diff: Move diff stat addition to a common function
Date: Fri, 11 Apr 2014 08:20:03 -0400 [thread overview]
Message-ID: <1397218805-2560-2-git-send-email-a.kumar@alumni.iitm.ac.in> (raw)
In-Reply-To: <1397218805-2560-1-git-send-email-a.kumar@alumni.iitm.ac.in>
Signed-off-by: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
---
include/tig/diff.h | 1 +
src/diff.c | 27 ++++++++++++++++++---------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/include/tig/diff.h b/include/tig/diff.h
index be325c4..ba40386 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -27,6 +27,7 @@ enum request diff_common_edit(struct view *view, enum request request, struct li
bool diff_common_read(struct view *view, const char *data, struct diff_state *state);
bool diff_common_draw(struct view *view, struct line *line, unsigned int lineno);
enum request diff_common_enter(struct view *view, enum request request, struct line *line);
+bool diff_common_add_diff_stat(struct view *view, const char *data);
unsigned int diff_get_lineno(struct view *view, struct line *line);
const char *diff_get_pathname(struct view *view, struct line *line);
diff --git a/src/diff.c b/src/diff.c
index 4b30068..1daf8fa 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -38,6 +38,21 @@ diff_open(struct view *view, enum open_flags flags)
}
bool
+diff_common_add_diff_stat(struct view *view, const char *data)
+{
+ size_t len = strlen(data);
+ char *pipe = strchr(data, '|');
+ bool has_histogram = data[len - 1] == '-' || data[len - 1] == '+';
+ bool has_bin_diff = pipe && strstr(pipe, "Bin") && strstr(pipe, "->");
+ bool has_rename = data[len - 1] == '0' && (strstr(data, "=>") || !strncmp(data, " ...", 4));
+ bool has_no_change = pipe && strstr(pipe, " 0");
+
+ if (pipe && (has_histogram || has_bin_diff || has_rename || has_no_change))
+ return add_line_text(view, data, LINE_DIFF_STAT) != NULL;
+ return FALSE;
+}
+
+bool
diff_common_read(struct view *view, const char *data, struct diff_state *state)
{
enum line_type type = get_line_type(data);
@@ -49,15 +64,9 @@ diff_common_read(struct view *view, const char *data, struct diff_state *state)
state->reading_diff_stat = TRUE;
if (state->reading_diff_stat) {
- size_t len = strlen(data);
- char *pipe = strchr(data, '|');
- bool has_histogram = data[len - 1] == '-' || data[len - 1] == '+';
- bool has_bin_diff = pipe && strstr(pipe, "Bin") && strstr(pipe, "->");
- bool has_rename = data[len - 1] == '0' && (strstr(data, "=>") || !strncmp(data, " ...", 4));
- bool has_no_change = pipe && strstr(pipe, " 0");
-
- if (pipe && (has_histogram || has_bin_diff || has_rename || has_no_change)) {
- return add_line_text(view, data, LINE_DIFF_STAT) != NULL;
+ bool ret = diff_common_add_diff_stat(view, data);
+ if (ret) {
+ return TRUE;
} else {
state->reading_diff_stat = FALSE;
}
--
1.9.1
next prev parent reply other threads:[~2014-04-11 12:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-11 12:20 [tig] [PATCH 0/3] log: colour the diffstat Kumar Appaiah
2014-04-11 12:20 ` Kumar Appaiah [this message]
2014-04-11 12:20 ` [tig] [PATCH 2/3] diff: Move diff stat drawing to a common function Kumar Appaiah
2014-04-11 12:20 ` [tig] [PATCH 3/3] log: Colour the diff stat Kumar Appaiah
2014-04-13 21:54 ` [tig] [PATCHv2 0/3] log: colour the diffstat Kumar Appaiah
2014-04-13 21:54 ` [tig] [PATCHv2 1/3] diff: Move diff stat addition to a common function Kumar Appaiah
2014-04-13 21:54 ` [tig] [PATCHv2 2/3] diff: Move diff stat drawing " Kumar Appaiah
2014-04-13 21:54 ` [tig] [PATCHv2 3/3] log: Colour the diff stat Kumar Appaiah
2014-04-17 0:44 ` Jonas Fonseca
2014-04-17 1:04 ` Kumar Appaiah
2014-04-17 0:52 ` [tig] [PATCHv2 0/3] log: colour the diffstat Jonas Fonseca
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=1397218805-2560-2-git-send-email-a.kumar@alumni.iitm.ac.in \
--to=a.kumar@alumni.iitm.ac.in \
--cc=git@vger.kernel.org \
--cc=jonas.fonseca@gmail.com \
/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).