From: Will Palmer <wmpalmer@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
Will Palmer <wmpalmer@gmail.com>
Subject: [PATCH/RFC 7/9] add long form %(color:...) for %C(...)
Date: Tue, 29 Mar 2011 00:17:29 +0100 [thread overview]
Message-ID: <1301354251-23380-8-git-send-email-wmpalmer@gmail.com> (raw)
In-Reply-To: <1301354251-23380-1-git-send-email-wmpalmer@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2011-03-28 23:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-28 23:17 [PATCH/RFC 0/9] add long forms for format placeholders Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 1/9] mention --date=raw in rev-list and blame help Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 2/9] add support for --date=unix to complement %at Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 3/9] interpret %C(invalid) as we would %%C(invalid) Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 4/9] add sanity length check to format_person_part Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 5/9] refactor pretty.c into "parse" and "format" steps Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 6/9] add long-form %(wrap:...) for %w(...) Will Palmer
2011-03-28 23:17 ` Will Palmer [this message]
2011-03-28 23:17 ` [PATCH/RFC 8/9] add long forms %(authordate) and %(committerdate) Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 9/9] add long forms for author and committer identity Will Palmer
2011-03-29 0:28 ` [PATCH/RFC 0/9] add long forms for format placeholders Junio C Hamano
2011-03-29 6:44 ` Will Palmer
2011-03-29 6:46 ` Michael J Gruber
2011-03-29 7:27 ` Will Palmer
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=1301354251-23380-8-git-send-email-wmpalmer@gmail.com \
--to=wmpalmer@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).