git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Quirk <richard.quirk@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Richard Quirk <richard.quirk@gmail.com>
Subject: [PATCH] git-cherry: add color to the output
Date: Fri,  2 May 2008 20:01:44 +0200	[thread overview]
Message-ID: <1209751304-25304-1-git-send-email-richard.quirk@gmail.com> (raw)

If color.diff is set then patches not yet cherry-picked are marked green
and already picked ones are marked red. This makes it easier to tell at a
glance which changes have not been cherry-picked.

A possible inconsistency is that the sha1 is marked in red or green here
whereas it is yellow elsewhere. The other possibility was to mark only
the +/- sign in the appropriate color, but this was more difficult to
distinguish between not-picked/picked changes.

Signed-off-by: Richard Quirk <richard.quirk@gmail.com>
---
 builtin-log.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index 1670d0b..bca6dd7 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -1083,6 +1083,11 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 	const char *limit = NULL;
 	int verbose = 0;
 
+	git_config(git_log_config);
+
+	if (diff_use_color_default == -1)
+		diff_use_color_default = git_use_color_default;
+
 	if (argc > 1 && !strcmp(argv[1], "-v")) {
 		verbose = 1;
 		argc--;
@@ -1136,26 +1141,32 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 
 		commit_list_insert(commit, &list);
 	}
+	const char *reset = diff_get_color(diff_use_color_default, DIFF_RESET);
+	const char *old = diff_get_color(diff_use_color_default, DIFF_FILE_OLD);
+	const char *new = diff_get_color(diff_use_color_default, DIFF_FILE_NEW);
 
 	while (list) {
 		char sign = '+';
+		const char * line_color = new;
 
 		commit = list->item;
-		if (has_commit_patch_id(commit, &ids))
+		if (has_commit_patch_id(commit, &ids)) {
 			sign = '-';
+			line_color = old;
+		}
 
+		printf("%s%c %s%s", line_color, sign,
+		       sha1_to_hex(commit->object.sha1), reset);
 		if (verbose) {
 			struct strbuf buf;
 			strbuf_init(&buf, 0);
 			pretty_print_commit(CMIT_FMT_ONELINE, commit,
 			                    &buf, 0, NULL, NULL, 0, 0);
-			printf("%c %s %s\n", sign,
-			       sha1_to_hex(commit->object.sha1), buf.buf);
+			printf(" %s\n", buf.buf);
 			strbuf_release(&buf);
 		}
 		else {
-			printf("%c %s\n", sign,
-			       sha1_to_hex(commit->object.sha1));
+			printf("\n");
 		}
 
 		list = list->next;
-- 
1.5.5.1.116.ge4b9c

             reply	other threads:[~2008-05-02 18:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-02 18:01 Richard Quirk [this message]
2008-05-05  3:27 ` [PATCH] git-cherry: add color to the output Jeff King
2008-05-05  5:14   ` Junio C Hamano

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=1209751304-25304-1-git-send-email-richard.quirk@gmail.com \
    --to=richard.quirk@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).