# [tig] [PATCH 0/3] log: colour the diffstat.

11 messages from 2014-04-11 to 2014-04-17. Participants: Kumar Appaiah, Jonas Fonseca.
Thread: https://gitlist.dev/t/36390

## Kumar Appaiah, 2014-04-11 12:20

Subject: [tig] [PATCH 0/3] log: colour the diffstat.
Message-ID: <1397218805-2560-1-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397218805-2560-1-git-send-email-a.kumar%40alumni.iitm.ac.in

```
These patches add colourization to the log view. They reuse the diff
stat drawing functions from the diff module directly.

Kumar Appaiah (3):
  diff: Move diff stat addition to a common function
  diff: Move diff stat drawing to a common function
  log: Colour the diff stat

 include/tig/diff.h |  2 ++
 src/diff.c         | 57 +++++++++++++++++++++++++++++++------------------
 src/log.c          | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 98 insertions(+), 23 deletions(-)

-- 
1.9.1

```

## Kumar Appaiah, 2014-04-11 12:20

Subject: [tig] [PATCH 1/3] diff: Move diff stat addition to a common function
Message-ID: <1397218805-2560-2-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397218805-2560-2-git-send-email-a.kumar%40alumni.iitm.ac.in
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

```

## Kumar Appaiah, 2014-04-11 12:20

Subject: [tig] [PATCH 2/3] diff: Move diff stat drawing to a common function
Message-ID: <1397218805-2560-3-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397218805-2560-3-git-send-email-a.kumar%40alumni.iitm.ac.in
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         | 30 ++++++++++++++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/include/tig/diff.h b/include/tig/diff.h
index ba40386..16299fe 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -28,6 +28,7 @@ bool diff_common_read(struct view *view, const char *data, struct diff_state *st
 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);
+void diff_common_draw_diff_stat(struct view *view, enum line_type *type, char **text);
 
 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 1daf8fa..b204bab 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -167,6 +167,23 @@ diff_common_draw_part(struct view *view, enum line_type *type, char **text, char
 	return sep != NULL;
 }
 
+void
+diff_common_draw_diff_stat(struct view *view, enum line_type *type, char **text)
+{
+		diff_common_draw_part(view, type, text, '|', LINE_DEFAULT);
+		if (diff_common_draw_part(view, type, text, 'B', LINE_DEFAULT)) {
+			/* Handle binary diffstat: Bin <deleted> -> <added> bytes */
+			diff_common_draw_part(view, type, text, ' ', LINE_DIFF_DEL);
+			diff_common_draw_part(view, type, text, '-', LINE_DEFAULT);
+			diff_common_draw_part(view, type, text, ' ', LINE_DIFF_ADD);
+			diff_common_draw_part(view, type, text, 'b', LINE_DEFAULT);
+
+		} else {
+			diff_common_draw_part(view, type, text, '+', LINE_DIFF_ADD);
+			diff_common_draw_part(view, type, text, '-', LINE_DIFF_DEL);
+		}
+}
+
 bool
 diff_common_draw(struct view *view, struct line *line, unsigned int lineno)
 {
@@ -180,18 +197,7 @@ diff_common_draw(struct view *view, struct line *line, unsigned int lineno)
 		return TRUE;
 
 	if (type == LINE_DIFF_STAT) {
-		diff_common_draw_part(view, &type, &text, '|', LINE_DEFAULT);
-		if (diff_common_draw_part(view, &type, &text, 'B', LINE_DEFAULT)) {
-			/* Handle binary diffstat: Bin <deleted> -> <added> bytes */
-			diff_common_draw_part(view, &type, &text, ' ', LINE_DIFF_DEL);
-			diff_common_draw_part(view, &type, &text, '-', LINE_DEFAULT);
-			diff_common_draw_part(view, &type, &text, ' ', LINE_DIFF_ADD);
-			diff_common_draw_part(view, &type, &text, 'b', LINE_DEFAULT);
-
-		} else {
-			diff_common_draw_part(view, &type, &text, '+', LINE_DIFF_ADD);
-			diff_common_draw_part(view, &type, &text, '-', LINE_DIFF_DEL);
-		}
+		diff_common_draw_diff_stat(view, &type, &text);
 	}
 
 	if (line->user_flags & DIFF_LINE_COMMIT_TITLE)
-- 
1.9.1

```

## Kumar Appaiah, 2014-04-11 12:20

Subject: [tig] [PATCH 3/3] log: Colour the diff stat
Message-ID: <1397218805-2560-4-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397218805-2560-4-git-send-email-a.kumar%40alumni.iitm.ac.in
In-Reply-To: <1397218805-2560-1-git-send-email-a.kumar@alumni.iitm.ac.in>

```
This commit adds custom log_read and log_draw functions that utilize
the diff stat drawing functions from the diff module. The absence of
the triple hyphen separator prevents direct usage of the diff drawing
functions directly.

Signed-Off-By: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
---
 src/log.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/log.c b/src/log.c
index eef61dc..e6f2a82 100644
--- a/src/log.c
+++ b/src/log.c
@@ -23,6 +23,9 @@ struct log_state {
 	 * up/down in the log view. */
 	int last_lineno;
 	enum line_type last_type;
+	bool commit_title_read;
+	bool after_commit_header;
+	bool reading_diff_stat;
 };
 
 static void
@@ -76,14 +79,69 @@ log_request(struct view *view, enum request request, struct line *line)
 	}
 }
 
+static bool
+log_read(struct view *view, char *data)
+{
+	enum line_type type;
+	struct log_state *state = view->private;
+	size_t len;
+
+	if (!data)
+		return TRUE;
+
+	type = get_line_type(data);
+
+	len = strlen(data);
+
+	if (type == LINE_COMMIT)
+		state->commit_title_read = TRUE;
+	else if (state->commit_title_read && len < 1) {
+		state->commit_title_read = FALSE;
+		state->after_commit_header = TRUE;
+	} else if (state->after_commit_header && len < 1) {
+		state->after_commit_header = FALSE;
+		state->reading_diff_stat = TRUE;
+	} else if (state->reading_diff_stat) {
+		bool ret = diff_common_add_diff_stat(view, data);
+		if (ret) {
+			return TRUE;
+		} else {
+			state->reading_diff_stat = FALSE;
+		}
+	}
+
+	return pager_common_read(view, data, type);
+}
+
+static bool
+log_draw(struct view *view, struct line *line, unsigned int lineno)
+{
+	char *text = line->data;
+	enum line_type type = line->type;
+
+	if (draw_lineno(view, lineno))
+		return TRUE;
+
+	if (line->wrapped && draw_text(view, LINE_DELIMITER, "+"))
+		return TRUE;
+
+	if (type == LINE_DIFF_STAT) {
+		diff_common_draw_diff_stat(view, &type, &text);
+		draw_text(view, type, text);
+		return TRUE;
+	}
+
+	return pager_draw(view, line, lineno);
+}
+
 static struct view_ops log_ops = {
 	"line",
 	argv_env.head,
 	VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_LOG_LIKE | VIEW_REFRESH,
 	sizeof(struct log_state),
 	log_open,
-	pager_read,
-	pager_draw,
+	log_read,
+	log_draw,
 	log_request,
 	pager_grep,
 	log_select,
-- 
1.9.1

```

## Kumar Appaiah, 2014-04-13 21:54

Subject: [tig] [PATCHv2 0/3] log: colour the diffstat
Message-ID: <1397426068-17439-1-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397426068-17439-1-git-send-email-a.kumar%40alumni.iitm.ac.in
In-Reply-To: <1397218805-2560-1-git-send-email-a.kumar@alumni.iitm.ac.in>

```
These patches add colourization to the log view. They reuse the diff
stat drawing functions from the diff module directly.

This version just includes some code reformatting and minor
fixes. Please comment on what other fixes could help.

Thanks.

Kumar Appaiah (3):
  diff: Move diff stat addition to a common function
  diff: Move diff stat drawing to a common function
  log: Colour the diff stat

 include/tig/diff.h |  2 ++
 src/diff.c         | 57 ++++++++++++++++++++++++++++++++++--------------------
 src/log.c          | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 91 insertions(+), 23 deletions(-)

-- 
1.9.1

```

## Kumar Appaiah, 2014-04-13 21:54

Subject: [tig] [PATCHv2 1/3] diff: Move diff stat addition to a common function
Message-ID: <1397426068-17439-2-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397426068-17439-2-git-send-email-a.kumar%40alumni.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

```

## Kumar Appaiah, 2014-04-13 21:54

Subject: [tig] [PATCHv2 2/3] diff: Move diff stat drawing to a common function
Message-ID: <1397426068-17439-3-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397426068-17439-3-git-send-email-a.kumar%40alumni.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         | 30 ++++++++++++++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/include/tig/diff.h b/include/tig/diff.h
index ba40386..16299fe 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -28,6 +28,7 @@ bool diff_common_read(struct view *view, const char *data, struct diff_state *st
 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);
+void diff_common_draw_diff_stat(struct view *view, enum line_type *type, char **text);
 
 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 1daf8fa..b204bab 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -167,6 +167,23 @@ diff_common_draw_part(struct view *view, enum line_type *type, char **text, char
 	return sep != NULL;
 }
 
+void
+diff_common_draw_diff_stat(struct view *view, enum line_type *type, char **text)
+{
+		diff_common_draw_part(view, type, text, '|', LINE_DEFAULT);
+		if (diff_common_draw_part(view, type, text, 'B', LINE_DEFAULT)) {
+			/* Handle binary diffstat: Bin <deleted> -> <added> bytes */
+			diff_common_draw_part(view, type, text, ' ', LINE_DIFF_DEL);
+			diff_common_draw_part(view, type, text, '-', LINE_DEFAULT);
+			diff_common_draw_part(view, type, text, ' ', LINE_DIFF_ADD);
+			diff_common_draw_part(view, type, text, 'b', LINE_DEFAULT);
+
+		} else {
+			diff_common_draw_part(view, type, text, '+', LINE_DIFF_ADD);
+			diff_common_draw_part(view, type, text, '-', LINE_DIFF_DEL);
+		}
+}
+
 bool
 diff_common_draw(struct view *view, struct line *line, unsigned int lineno)
 {
@@ -180,18 +197,7 @@ diff_common_draw(struct view *view, struct line *line, unsigned int lineno)
 		return TRUE;
 
 	if (type == LINE_DIFF_STAT) {
-		diff_common_draw_part(view, &type, &text, '|', LINE_DEFAULT);
-		if (diff_common_draw_part(view, &type, &text, 'B', LINE_DEFAULT)) {
-			/* Handle binary diffstat: Bin <deleted> -> <added> bytes */
-			diff_common_draw_part(view, &type, &text, ' ', LINE_DIFF_DEL);
-			diff_common_draw_part(view, &type, &text, '-', LINE_DEFAULT);
-			diff_common_draw_part(view, &type, &text, ' ', LINE_DIFF_ADD);
-			diff_common_draw_part(view, &type, &text, 'b', LINE_DEFAULT);
-
-		} else {
-			diff_common_draw_part(view, &type, &text, '+', LINE_DIFF_ADD);
-			diff_common_draw_part(view, &type, &text, '-', LINE_DIFF_DEL);
-		}
+		diff_common_draw_diff_stat(view, &type, &text);
 	}
 
 	if (line->user_flags & DIFF_LINE_COMMIT_TITLE)
-- 
1.9.1

```

## Kumar Appaiah, 2014-04-13 21:54

Subject: [tig] [PATCHv2 3/3] log: Colour the diff stat
Message-ID: <1397426068-17439-4-git-send-email-a.kumar@alumni.iitm.ac.in>
URL: https://gitlist.dev/e/1397426068-17439-4-git-send-email-a.kumar%40alumni.iitm.ac.in
In-Reply-To: <1397426068-17439-1-git-send-email-a.kumar@alumni.iitm.ac.in>

```
This commit adds custom log_read and log_draw functions that utilize
the diff stat drawing functions from the diff module. The absence of
the triple hyphen separator prevents direct usage of the diff drawing
functions directly.

Signed-Off-By: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
---
 src/log.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/log.c b/src/log.c
index 40c9a21..468f7c3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -23,6 +23,9 @@ struct log_state {
 	 * up/down in the log view. */
 	int last_lineno;
 	enum line_type last_type;
+	bool commit_title_read;
+	bool after_commit_header;
+	bool reading_diff_stat;
 };
 
 static void
@@ -78,14 +81,62 @@ log_request(struct view *view, enum request request, struct line *line)
 	}
 }
 
+static bool
+log_read(struct view *view, char *data)
+{
+	enum line_type type;
+	struct log_state *state = view->private;
+	size_t len;
+
+	if (!data)
+		return TRUE;
+
+	type = get_line_type(data);
+	len = strlen(data);
+
+	if (type == LINE_COMMIT)
+		state->commit_title_read = TRUE;
+	else if (state->commit_title_read && len < 1) {
+		state->commit_title_read = FALSE;
+		state->after_commit_header = TRUE;
+	} else if (state->after_commit_header && len < 1) {
+		state->after_commit_header = FALSE;
+		state->reading_diff_stat = TRUE;
+	} else if (state->reading_diff_stat) {
+		bool ret = diff_common_add_diff_stat(view, data);
+		if (ret) {
+			return TRUE;
+		} else {
+			state->reading_diff_stat = FALSE;
+		}
+	}
+
+	return pager_common_read(view, data, type);
+}
+
+static bool
+log_draw(struct view *view, struct line *line, unsigned int lineno)
+{
+	char *text = line->data;
+	enum line_type type = line->type;
+
+	if (type == LINE_DIFF_STAT) {
+		diff_common_draw_diff_stat(view, &type, &text);
+		draw_text(view, type, text);
+		return TRUE;
+	}
+
+	return pager_draw(view, line, lineno);
+}
+
 static struct view_ops log_ops = {
 	"line",
 	argv_env.head,
 	VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_LOG_LIKE | VIEW_REFRESH,
 	sizeof(struct log_state),
 	log_open,
-	pager_read,
-	pager_draw,
+	log_read,
+	log_draw,
 	log_request,
 	pager_grep,
 	log_select,
-- 
1.9.1

```

## Jonas Fonseca, 2014-04-17 00:44

Subject: Re: [tig] [PATCHv2 3/3] log: Colour the diff stat
Message-ID: <CAFuPQ1JbpNcun3hGps=hwaM14wOjF+iU9bsm9+ZmJvJV_Fea4Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAFuPQ1JbpNcun3hGps%3DhwaM14wOjF%2BiU9bsm9%2BZmJvJV_Fea4Q%40mail.gmail.com
In-Reply-To: <1397426068-17439-4-git-send-email-a.kumar@alumni.iitm.ac.in>

```
On Sun, Apr 13, 2014 at 5:54 PM, Kumar Appaiah
<a.kumar@alumni.iitm.ac.in> wrote:
>
> This commit adds custom log_read and log_draw functions that utilize
> the diff stat drawing functions from the diff module. The absence of
> the triple hyphen separator prevents direct usage of the diff drawing
> functions directly.

See my comments below.

> ---
>  src/log.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 53 insertions(+), 2 deletions(-)
>
> diff --git a/src/log.c b/src/log.c
> index 40c9a21..468f7c3 100644
> --- a/src/log.c
> +++ b/src/log.c
> @@ -23,6 +23,9 @@ struct log_state {
>          * up/down in the log view. */
>         int last_lineno;
>         enum line_type last_type;
> +       bool commit_title_read;
> +       bool after_commit_header;
> +       bool reading_diff_stat;
>  };
>
>  static void
> @@ -78,14 +81,62 @@ log_request(struct view *view, enum request request, struct line *line)
>         }
>  }
>
> +static bool
> +log_read(struct view *view, char *data)
> +{
> +       enum line_type type;
> +       struct log_state *state = view->private;
> +       size_t len;
> +
> +       if (!data)
> +               return TRUE;
> +
> +       type = get_line_type(data);
> +       len = strlen(data);
> +
> +       if (type == LINE_COMMIT)
> +               state->commit_title_read = TRUE;
> +       else if (state->commit_title_read && len < 1) {
> +               state->commit_title_read = FALSE;
> +               state->after_commit_header = TRUE;
> +       } else if (state->after_commit_header && len < 1) {
> +               state->after_commit_header = FALSE;
> +               state->reading_diff_stat = TRUE;
> +       } else if (state->reading_diff_stat) {
> +               bool ret = diff_common_add_diff_stat(view, data);
> +               if (ret) {
> +                       return TRUE;
> +               } else {
> +                       state->reading_diff_stat = FALSE;
> +               }
> +       }
> +
> +       return pager_common_read(view, data, type);
> +}
> +
> +static bool
> +log_draw(struct view *view, struct line *line, unsigned int lineno)
> +{
> +       char *text = line->data;
> +       enum line_type type = line->type;
> +

This is missing a call to draw_lineno(...)

> +       if (type == LINE_DIFF_STAT) {
> +               diff_common_draw_diff_stat(view, &type, &text);
> +               draw_text(view, type, text);

I had to #include "tig/draw.h" for this to compile.

> +               return TRUE;
> +       }
> +
> +       return pager_draw(view, line, lineno);
> +}
> +
>  static struct view_ops log_ops = {
>         "line",
>         argv_env.head,
>         VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_LOG_LIKE | VIEW_REFRESH,
>         sizeof(struct log_state),
>         log_open,
> -       pager_read,
> -       pager_draw,
> +       log_read,
> +       log_draw,
>         log_request,
>         pager_grep,
>         log_select,
> --
> 1.9.1
>



-- 
Jonas Fonseca

```

## Jonas Fonseca, 2014-04-17 00:52

Subject: Re: [tig] [PATCHv2 0/3] log: colour the diffstat
Message-ID: <CAFuPQ1L=iW+kWXZ41BDKXzyMH0Ci87_qi79FCm14juiK=Qfh=A@mail.gmail.com>
URL: https://gitlist.dev/e/CAFuPQ1L%3DiW%2BkWXZ41BDKXzyMH0Ci87_qi79FCm14juiK%3DQfh%3DA%40mail.gmail.com
In-Reply-To: <1397426068-17439-1-git-send-email-a.kumar@alumni.iitm.ac.in>

```
Hi Kumar,

On Sun, Apr 13, 2014 at 5:54 PM, Kumar Appaiah
<a.kumar@alumni.iitm.ac.in> wrote:
>
> These patches add colourization to the log view. They reuse the diff
> stat drawing functions from the diff module directly.

This is a great idea. I wonder though if it would make sense to put
this into the pager backend instead so all pager based views can
benefit unless of course the "state machine" would end up becoming too
complicated.

> This version just includes some code reformatting and minor
> fixes. Please comment on what other fixes could help.

See my other email regarding fixes. Since I am currently refactoring
how views are drawn I'd prefer to postpone merging this patchset until
the dust has settled. I'll try to rebase the patches once I get there
before reaching out to you.

-- 
Jonas Fonseca

```

## Kumar Appaiah, 2014-04-17 01:04

Subject: Re: [tig] [PATCHv2 3/3] log: Colour the diff stat
Message-ID: <20140417010454.GA27665@odessa>
URL: https://gitlist.dev/e/20140417010454.GA27665%40odessa
In-Reply-To: <CAFuPQ1JbpNcun3hGps=hwaM14wOjF+iU9bsm9+ZmJvJV_Fea4Q@mail.gmail.com>

```

On Wed, Apr 16, 2014 at 08:44:41PM -0400, Jonas Fonseca wrote:
> On Sun, Apr 13, 2014 at 5:54 PM, Kumar Appaiah
> <a.kumar@alumni.iitm.ac.in> wrote:
> >
> > This commit adds custom log_read and log_draw functions that utilize
> > the diff stat drawing functions from the diff module. The absence of
> > the triple hyphen separator prevents direct usage of the diff drawing
> > functions directly.
> 
> See my comments below.

Hi Jonas.

> > +static bool
> > +log_draw(struct view *view, struct line *line, unsigned int lineno)
> > +{
> > +       char *text = line->data;
> > +       enum line_type type = line->type;
> > +
> 
> This is missing a call to draw_lineno(...)

Noted.

> > +       if (type == LINE_DIFF_STAT) {
> > +               diff_common_draw_diff_stat(view, &type, &text);
> > +               draw_text(view, type, text);
> 
> I had to #include "tig/draw.h" for this to compile.

I'll take care of this.

I'll send you a pull request eventually. You can handle it after your
refactor is complete.

Thanks!

Kumar
-- 
Kumar Appaiah

```
