From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 09/15] for-each-ref: teach verify_format() about pretty's syntax
Date: Tue, 9 Jul 2013 16:02:20 +0530 [thread overview]
Message-ID: <1373365946-9230-10-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1373365946-9230-1-git-send-email-artagnon@gmail.com>
From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Pretty format accepts either ' ', '+' or '-' after '%' and before the
placeholder name to modify certain behaviors. Teach verify_format()
about this so that it finds atom "upstream" in, for example,
'% (upstream)'. This is important because verify_format populates
used_atom, which get_value() and populate_value() later rely on.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
builtin/for-each-ref.c | 15 +++++++++------
pretty.c | 4 ++++
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 8611777..39454fb 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -150,7 +150,7 @@ static int parse_atom(const char *atom, const char *ep)
/*
* In a format string, find the next occurrence of %(atom).
*/
-static const char *find_next(const char *cp)
+static const char *find_next(const char *cp, int pretty)
{
while (*cp) {
if (*cp == '%') {
@@ -160,6 +160,9 @@ static const char *find_next(const char *cp)
*/
if (cp[1] == '(')
return cp;
+ else if (pretty && cp[1] && cp[2] == '(' &&
+ strchr(" +-", cp[1])) /* see format_commit_item() */
+ return cp + 1;
else if (cp[1] == '%')
cp++; /* skip over two % */
/* otherwise this is a singleton, literal % */
@@ -173,10 +176,10 @@ static const char *find_next(const char *cp)
* Make sure the format string is well formed, and parse out
* the used atoms.
*/
-static int verify_format(const char *format)
+static int verify_format(const char *format, int pretty)
{
const char *cp, *sp;
- for (cp = format; *cp && (sp = find_next(cp)); ) {
+ for (cp = format; *cp && (sp = find_next(cp, pretty)); ) {
const char *ep = strchr(sp, ')');
if (!ep)
return error("malformed format string %s", sp);
@@ -935,7 +938,7 @@ static void show_ref(struct strbuf *sb, struct refinfo *info,
{
const char *cp, *sp, *ep;
- for (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {
+ for (cp = format; *cp && (sp = find_next(cp, 0)); cp = ep + 1) {
ep = strchr(sp, ')');
if (cp < sp)
emit(sb, cp, sp);
@@ -1098,8 +1101,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
}
if (format != default_format && pretty)
die("--format and --pretty cannot be used together");
- if ((pretty && verify_format(pretty)) ||
- (!pretty && verify_format(format)))
+ if ((pretty && verify_format(pretty, 1)) ||
+ (!pretty && verify_format(format, 0)))
usage_with_options(for_each_ref_usage, opts);
if (!sort)
diff --git a/pretty.c b/pretty.c
index 816aa32..28c0a72 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1439,6 +1439,10 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */
ADD_SP_BEFORE_NON_EMPTY
} magic = NO_MAGIC;
+ /*
+ * Note: any modification in what placeholder[0] contains
+ * should be redone in builtin/for-each-ref.c:find_next().
+ */
switch (placeholder[0]) {
case '-':
magic = DEL_LF_BEFORE_EMPTY;
--
1.8.3.2.736.g869de25
next prev parent reply other threads:[~2013-07-09 10:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-09 10:32 [RESEND][PATCH 00/15] Towards a more awesome git branch Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 01/15] for-each-ref, quote: convert *_quote_print -> *_quote_buf Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 02/15] for-each-ref: don't print out elements directly Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 03/15] tar-tree: remove dependency on sq_quote_print() Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 04/15] quote: remove sq_quote_print() Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 05/15] pretty: extend pretty_print_context with callback Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 06/15] pretty: limit recursion in format_commit_one() Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 07/15] pretty: allow passing NULL commit to format_commit_message() Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 08/15] for-each-ref: get --pretty using format_commit_message() Ramkumar Ramachandra
2013-07-09 10:32 ` Ramkumar Ramachandra [this message]
2013-07-09 10:32 ` [PATCH 10/15] for-each-ref: introduce format specifier %>(*) and %<(*) Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 11/15] for-each-ref: introduce %(HEAD) marker Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 12/15] for-each-ref: introduce %(upstream:track[short]) Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 13/15] for-each-ref: improve responsiveness of %(upstream:track) Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 14/15] pretty: introduce get_pretty_userformat Ramkumar Ramachandra
2013-07-09 10:32 ` [PATCH 15/15] for-each-ref: use get_pretty_userformat in --pretty Ramkumar Ramachandra
2013-07-13 12:31 ` [RESEND][PATCH 00/15] Towards a more awesome git branch Duy Nguyen
-- strict thread matches above, loose matches on Subject: below --
2013-06-04 12:35 [PATCH 00/15] Towards a more awesome git-branch Ramkumar Ramachandra
2013-06-04 12:35 ` [PATCH 09/15] for-each-ref: teach verify_format() about pretty's syntax Ramkumar Ramachandra
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1373365946-9230-10-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).