git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-cherry: add color to the output
@ 2008-05-02 18:01 Richard Quirk
  2008-05-05  3:27 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Quirk @ 2008-05-02 18:01 UTC (permalink / raw)
  To: gitster; +Cc: git, Richard Quirk

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

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

* Re: [PATCH] git-cherry: add color to the output
  2008-05-02 18:01 [PATCH] git-cherry: add color to the output Richard Quirk
@ 2008-05-05  3:27 ` Jeff King
  2008-05-05  5:14   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2008-05-05  3:27 UTC (permalink / raw)
  To: Richard Quirk; +Cc: gitster, git

On Fri, May 02, 2008 at 08:01:44PM +0200, Richard Quirk wrote:

> 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.

I don't actually use git-cherry, so I can't say whether this is useful
or not. But I wonder if it should follow the trend of other color
options and get its own color.cherry variable, but also be controlled by
the master color.ui.

-Peff

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

* Re: [PATCH] git-cherry: add color to the output
  2008-05-05  3:27 ` Jeff King
@ 2008-05-05  5:14   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2008-05-05  5:14 UTC (permalink / raw)
  To: Jeff King; +Cc: Richard Quirk, gitster, git

Jeff King <peff@peff.net> writes:

> On Fri, May 02, 2008 at 08:01:44PM +0200, Richard Quirk wrote:
>
>> 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.
>
> I don't actually use git-cherry, so I can't say whether this is useful
> or not. But I wonder if it should follow the trend of other color
> options and get its own color.cherry variable, but also be controlled by
> the master color.ui.

I do not use git-cherry as Porcelain nor did I design it to be used as
such.  "color.cherry = always" would worry me but the user is asking for
trouble if he did so, so perhaps it is Ok.

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

end of thread, other threads:[~2008-05-05  5:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-02 18:01 [PATCH] git-cherry: add color to the output Richard Quirk
2008-05-05  3:27 ` Jeff King
2008-05-05  5:14   ` Junio C Hamano

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).