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

[tig] [PATCHv2 1/3] diff: Move diff stat addition to a common function

From
Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
Date
Apr 13, 2014, 21:54 UTC
Message-ID
<1397426068-17439-2-git-send-email-a.kumar@alumni.iitm.ac.in>
In-Reply-To
<1397426068-17439-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
Previous: Kumar AppaiahNext: Kumar Appaiah
Message 6 of 11 in “log: colour the diffstat.”
  1. Kumar AppaiahApr 11, 2014
  2. [tig] [PATCH 1/3] diff: Move diff stat addition to a common functionKumar Appaiah, Apr 11, 2014
  3. [tig] [PATCH 2/3] diff: Move diff stat drawing to a common functionKumar Appaiah, Apr 11, 2014
  4. [tig] [PATCH 3/3] log: Colour the diff statKumar Appaiah, Apr 11, 2014
  5. [tig] [PATCHv2 0/3] log: colour the diffstatKumar Appaiah, Apr 13, 2014
  6. [tig] [PATCHv2 1/3] diff: Move diff stat addition to a common functionKumar Appaiah, Apr 13, 2014
  7. [tig] [PATCHv2 2/3] diff: Move diff stat drawing to a common functionKumar Appaiah, Apr 13, 2014
  8. [tig] [PATCHv2 3/3] log: Colour the diff statKumar Appaiah, Apr 13, 2014
  9. Jonas FonsecaApr 17, 2014
  10. Kumar AppaiahApr 17, 2014
  11. Jonas FonsecaApr 17, 2014

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.