From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Thomas Rast <trast@student.ethz.ch>,
Johannes Gilger <heipei@hackvalue.de>,
Git ML <git@vger.kernel.org>
Subject: Re: [PATCH] Initialize notes trees if %N is used and no --show-notes given
Date: Wed, 7 Apr 2010 02:36:42 -0400 [thread overview]
Message-ID: <20100407063642.GA5399@coredump.intra.peff.net> (raw)
In-Reply-To: <7v39z7g4zp.fsf@alter.siamese.dyndns.org>
On Tue, Apr 06, 2010 at 11:18:34PM -0700, Junio C Hamano wrote:
> As Peff pointed out, %d does things lazily, but I suspect it might be hard
> to do a similar initialization for %N.
I think you would just have to stuff the notes-related options from the
rev-list options into the pretty-print context, which would then make
them available to the user-format callback.
> I wonder if we can inspect-but-not-use format string before we even start
> walking, to see if we need notes (when we see %N).
I have considered something like the patch below before, but it is not
100% accurate. Part of the parsing happens in strbuf_expand, but parsing
of things like %w(...) happens ad-hoc inside the formatting callback (so
we would see "%w(%N)" as wanting notes, when it doesn't really. In
theory it would be nicer if we separated syntax and semantics, so I
could parse %X(...) as "the %X placeholder with ... as arguments"
without having to actually understand what %X does. In practice, it
doesn't matter here because we don't have very many placeholders that
take arbitrary arguments.
The patch below is totally untested and just meant to illustrate the
approach. Use caution.
diff --git a/commit.h b/commit.h
index 2b7fd89..5081389 100644
--- a/commit.h
+++ b/commit.h
@@ -74,11 +74,16 @@ struct pretty_print_context
struct reflog_walk_info *reflog_info;
};
+struct userformat_want {
+ unsigned notes:1;
+};
+
extern int has_non_ascii(const char *text);
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
extern char *reencode_commit_message(const struct commit *commit,
const char **encoding_p);
extern void get_commit_format(const char *arg, struct rev_info *);
+extern void userformat_fill_want(const char *format, struct userformat_want *w);
extern void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *context);
diff --git a/pretty.c b/pretty.c
index 6ba3da8..8ed3d36 100644
--- a/pretty.c
+++ b/pretty.c
@@ -855,6 +855,24 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
return consumed + 1;
}
+static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
+ void *context)
+{
+ struct userformat_want *w = context;
+ switch (*placeholder) {
+ case 'N': w->notes = 1;
+ }
+ return 0;
+}
+
+void userformat_fill_want(const char *format, struct userformat_want *w)
+{
+ struct strbuf dummy = STRBUF_INIT;
+ memset(w, 0, sizeof(*w));
+ strbuf_expand(&dummy, format, userformat_want_item, w);
+ strbuf_release(&dummy);
+}
+
void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *pretty_ctx)
next prev parent reply other threads:[~2010-04-07 6:37 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-05 11:55 [PATCH] Initialize notes trees if %N is used and no --show-notes given Johannes Gilger
2010-04-06 5:32 ` Jeff King
2010-04-06 9:27 ` Thomas Rast
2010-04-06 11:19 ` Johannes Gilger
2010-04-06 11:52 ` Thomas Rast
2010-04-06 16:22 ` Jeff King
2010-04-07 6:18 ` Junio C Hamano
2010-04-07 6:36 ` Jeff King [this message]
2010-04-10 7:05 ` [PATCH] pretty.c: Don't expand %N without --show-notes Johannes Gilger
2010-04-10 20:00 ` Junio C Hamano
2010-04-10 21:30 ` [PATCH] Notes: Connect the %N flag to --{show,no}-notes Johannes Gilger
2010-04-10 21:51 ` Junio C Hamano
2010-04-10 22:08 ` Jeff King
2010-04-11 14:54 ` [PATCH] pretty: Initialize notes if %N is used Johannes Gilger
2010-04-12 8:56 ` Jeff King
2010-04-13 8:59 ` [PATCHv2] " Johannes Gilger
2010-04-13 10:03 ` Jeff King
2010-04-13 10:36 ` Johannes Gilger
2010-04-13 10:57 ` [PATCHv3] " y
2010-04-13 10:57 ` y
2010-04-13 11:01 ` Johannes Gilger
2010-04-13 11:07 ` Jeff King
2010-04-13 11:26 ` [PATCHv4] " Johannes Gilger
2010-04-13 20:01 ` Junio C Hamano
2010-04-13 20:31 ` [PATCHv5] " Johannes Gilger
2010-04-10 22:20 ` [PATCH] Notes: Connect the %N flag to --{show,no}-notes Johannes Gilger
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=20100407063642.GA5399@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=heipei@hackvalue.de \
--cc=trast@student.ethz.ch \
/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).