[PATCH/RFC 7/9] add long form %(color:...) for %C(...)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



this adds %(color:...) as an alternative to %C(...) in the "git log"
family of commands. We now have a "long form" for all of the existing
complex placeholders.

Signed-off-by: Will Palmer <wmpalmer@xxxxxxxxx>
---
 Documentation/pretty-formats.txt |    1 +
 pretty.c                         |   22 ++++++++++++++++++++++
 test-pretty.c                    |    1 +
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index c9f3fb6..d987102 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -138,6 +138,7 @@ The placeholders are:
 - '%Cblue': switch color to blue
 - '%Creset': reset color
 - '%C(...)': color specification, as described in color.branch.* config option
+- '%(color:...)': alternative form of %C(...)
 - '%m': left, right or boundary mark
 - '%n': newline
 - '%%': a raw '%'
diff --git a/pretty.c b/pretty.c
index 8301008..616b857 100644
--- a/pretty.c
+++ b/pretty.c
@@ -126,9 +126,31 @@ static struct format_part *parse_extended(const char *unparsed)
 {
 	struct format_part *part = format_part_alloc();
 	const char *c = unparsed + 2; /* "%(..." + strlen("%(") */
+	const char *e;
 
 	c += strspn(c, WHITESPACE);
 
+	if (!prefixcmp(c, "color")) {
+		part->type = FORMAT_PART_LITERAL;
+		c += 5 + strspn(c + 5, WHITESPACE);
+		if (*c == ')') {
+			part->literal = xstrdup(GIT_COLOR_RESET);
+			part->literal_len = strlen(part->literal);
+			goto success;
+		}
+		if (*c != ':')
+			goto fail;
+		c++;
+		e = strchr(c, ')');
+		part->literal = xcalloc(1, COLOR_MAXLEN);
+		if (!e || !color_parse_len(c, e - c,
+					   part->literal))
+			goto fail;
+		part->literal_len = strlen(part->literal);
+		c = e;
+		goto success;
+	}
+
 	if (!prefixcmp(c, "wrap")) {
 		part->type = FORMAT_PART_WRAP;
 		c += 4;
diff --git a/test-pretty.c b/test-pretty.c
index 64a8218..eb88e3a 100644
--- a/test-pretty.c
+++ b/test-pretty.c
@@ -18,6 +18,7 @@ static const char *all = "a"
 "%Cred%Cgreen%Cblue%Creset%C(reset)"
 "%m%w()%w(1)%w(1,2)%w(1,2,3)"
 "%(wrap)%(wrap:1)%(wrap:1,2)%(wrap:1,2,3)"
+"%(color)%(color:red)%(color:red bold)%(color:red green bold)"
 "%x0a%n%%%@";
 
 static struct strbuf *parts_debug(struct format_parts *parts,
-- 
1.7.4.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]