git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 3/3] log: Colour the diff stat
Date: Fri, 11 Apr 2014 08:20:05 -0400	[thread overview]
Message-ID: <1397218805-2560-4-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>

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

  parent reply	other threads:[~2014-04-11 12:51 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 ` [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 [this message]
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-4-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).