All of lore.kernel.org
 help / color / mirror / Atom feed
* [tig] [PATCH 0/3] log: colour the diffstat.
@ 2014-04-11 12:20 Kumar Appaiah
  2014-04-11 12:20 ` [tig] [PATCH 1/3] diff: Move diff stat addition to a common function Kumar Appaiah
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-11 12:20 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tig] [PATCH 1/3] diff: Move diff stat addition to a common function
  2014-04-11 12:20 [tig] [PATCH 0/3] log: colour the diffstat Kumar Appaiah
@ 2014-04-11 12:20 ` Kumar Appaiah
  2014-04-11 12:20 ` [tig] [PATCH 2/3] diff: Move diff stat drawing " Kumar Appaiah
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-11 12:20 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tig] [PATCH 2/3] diff: Move diff stat drawing to a common function
  2014-04-11 12:20 [tig] [PATCH 0/3] log: colour the diffstat Kumar Appaiah
  2014-04-11 12:20 ` [tig] [PATCH 1/3] diff: Move diff stat addition to a common function Kumar Appaiah
@ 2014-04-11 12:20 ` 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
  3 siblings, 0 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-11 12:20 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tig] [PATCH 3/3] log: Colour the diff stat
  2014-04-11 12:20 [tig] [PATCH 0/3] log: colour the diffstat Kumar Appaiah
  2014-04-11 12:20 ` [tig] [PATCH 1/3] diff: Move diff stat addition to a common function Kumar Appaiah
  2014-04-11 12:20 ` [tig] [PATCH 2/3] diff: Move diff stat drawing " Kumar Appaiah
@ 2014-04-11 12:20 ` Kumar Appaiah
  2014-04-13 21:54 ` [tig] [PATCHv2 0/3] log: colour the diffstat Kumar Appaiah
  3 siblings, 0 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-11 12:20 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tig] [PATCHv2 0/3] log: colour the diffstat
  2014-04-11 12:20 [tig] [PATCH 0/3] log: colour the diffstat Kumar Appaiah
                   ` (2 preceding siblings ...)
  2014-04-11 12:20 ` [tig] [PATCH 3/3] log: Colour the diff stat Kumar Appaiah
@ 2014-04-13 21:54 ` Kumar Appaiah
  2014-04-13 21:54   ` [tig] [PATCHv2 1/3] diff: Move diff stat addition to a common function Kumar Appaiah
                     ` (3 more replies)
  3 siblings, 4 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-13 21:54 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tig] [PATCHv2 1/3] diff: Move diff stat addition to a common function
  2014-04-13 21:54 ` [tig] [PATCHv2 0/3] log: colour the diffstat Kumar Appaiah
@ 2014-04-13 21:54   ` Kumar Appaiah
  2014-04-13 21:54   ` [tig] [PATCHv2 2/3] diff: Move diff stat drawing " Kumar Appaiah
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-13 21:54 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tig] [PATCHv2 2/3] diff: Move diff stat drawing to a common function
  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   ` Kumar Appaiah
  2014-04-13 21:54   ` [tig] [PATCHv2 3/3] log: Colour the diff stat Kumar Appaiah
  2014-04-17  0:52   ` [tig] [PATCHv2 0/3] log: colour the diffstat Jonas Fonseca
  3 siblings, 0 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-13 21:54 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tig] [PATCHv2 3/3] log: Colour the diff stat
  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   ` Kumar Appaiah
  2014-04-17  0:44     ` Jonas Fonseca
  2014-04-17  0:52   ` [tig] [PATCHv2 0/3] log: colour the diffstat Jonas Fonseca
  3 siblings, 1 reply; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-13 21:54 UTC (permalink / raw)
  To: Jonas Fonseca, git; +Cc: Kumar Appaiah

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [tig] [PATCHv2 3/3] log: Colour the diff stat
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Jonas Fonseca @ 2014-04-17  0:44 UTC (permalink / raw)
  To: Kumar Appaiah; +Cc: git

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [tig] [PATCHv2 0/3] log: colour the diffstat
  2014-04-13 21:54 ` [tig] [PATCHv2 0/3] log: colour the diffstat Kumar Appaiah
                     ` (2 preceding siblings ...)
  2014-04-13 21:54   ` [tig] [PATCHv2 3/3] log: Colour the diff stat Kumar Appaiah
@ 2014-04-17  0:52   ` Jonas Fonseca
  3 siblings, 0 replies; 11+ messages in thread
From: Jonas Fonseca @ 2014-04-17  0:52 UTC (permalink / raw)
  To: Kumar Appaiah; +Cc: git

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [tig] [PATCHv2 3/3] log: Colour the diff stat
  2014-04-17  0:44     ` Jonas Fonseca
@ 2014-04-17  1:04       ` Kumar Appaiah
  0 siblings, 0 replies; 11+ messages in thread
From: Kumar Appaiah @ 2014-04-17  1:04 UTC (permalink / raw)
  To: Jonas Fonseca; +Cc: git


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-04-17  1:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-11 12:20 [tig] [PATCH 0/3] log: colour the diffstat Kumar Appaiah
2014-04-11 12:20 ` [tig] [PATCH 1/3] diff: Move diff stat addition to a common function Kumar Appaiah
2014-04-11 12:20 ` [tig] [PATCH 2/3] diff: Move diff stat drawing " 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.