git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-cherry: add color to the output

From
RQRichard Quirk <richard.quirk@gmail.com>
Date
May 2, 2008, 18:01 UTC
Message-ID
<1209751304-25304-1-git-send-email-richard.quirk@gmail.com>

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
Next: Jeff King
Message 1 of 3 in “git-cherry: add color to the output”
  1. git-cherry: add color to the outputRichard Quirk, May 2, 2008
  2. Jeff KingMay 5, 2008
  3. Junio C HamanoMay 5, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.