From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 3/3] add a "lua" pretty format
Date: Mon, 24 Sep 2012 20:25:39 -0400 [thread overview]
Message-ID: <20120925002539.GC19605@sigill.intra.peff.net> (raw)
In-Reply-To: <20120925002325.GA19560@sigill.intra.peff.net>
With this patch, you can do:
git log --pretty=lua:'
return abbrev(hash()) .. " (" .. author().email .. ") " .. subject()
'
Signed-off-by: Jeff King <peff@peff.net>
---
commit.h | 1 +
log-tree.c | 3 ++-
pretty.c | 21 +++++++++++++++++++--
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/commit.h b/commit.h
index 71cd4af..8865a36 100644
--- a/commit.h
+++ b/commit.h
@@ -73,6 +73,7 @@ enum cmit_fmt {
CMIT_FMT_ONELINE,
CMIT_FMT_EMAIL,
CMIT_FMT_USERFORMAT,
+ CMIT_FMT_LUA,
CMIT_FMT_UNSPECIFIED
};
diff --git a/log-tree.c b/log-tree.c
index c894930..c8274d1 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -599,7 +599,8 @@ void show_log(struct rev_info *opt)
if (opt->commit_format == CMIT_FMT_EMAIL) {
log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
&ctx.need_8bit_cte);
- } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
+ } else if (opt->commit_format != CMIT_FMT_USERFORMAT &&
+ opt->commit_format != CMIT_FMT_LUA) {
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
if (opt->commit_format != CMIT_FMT_ONELINE)
fputs("commit ", stdout);
diff --git a/pretty.c b/pretty.c
index 0d4eb3d..fdd4258 100644
--- a/pretty.c
+++ b/pretty.c
@@ -10,6 +10,7 @@
#include "color.h"
#include "reflog-walk.h"
#include "gpg-interface.h"
+#include "lua-commit.h"
static char *user_format;
static struct cmt_fmt_map {
@@ -33,6 +34,13 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma
rev->commit_format = CMIT_FMT_USERFORMAT;
}
+static void save_lua_format(struct rev_info *rev, const char *cp, int is_tformat)
+{
+ lua_commit_init(cp);
+ save_user_format(rev, cp, is_tformat);
+ rev->commit_format = CMIT_FMT_LUA;
+}
+
static int git_pretty_formats_config(const char *var, const char *value, void *cb)
{
struct cmt_fmt_map *commit_format = NULL;
@@ -155,6 +163,10 @@ void get_commit_format(const char *arg, struct rev_info *rev)
save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
return;
}
+ if (!prefixcmp(arg, "lua:")) {
+ save_lua_format(rev, arg + 4, 1);
+ return;
+ }
if (strchr(arg, '%')) {
save_user_format(rev, arg, 1);
@@ -1168,7 +1180,11 @@ void format_commit_message(const struct commit *commit,
free(enc);
}
- strbuf_expand(sb, format, format_commit_item, &context);
+ if (pretty_ctx->fmt == CMIT_FMT_USERFORMAT)
+ strbuf_expand(sb, format, format_commit_item, &context);
+ else if (pretty_ctx->fmt == CMIT_FMT_LUA)
+ lua_commit_format(sb, &context);
+
rewrap_message_tail(sb, &context, 0, 0, 0);
if (context.message != commit->buffer)
@@ -1328,7 +1344,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,
const char *encoding;
int need_8bit_cte = pp->need_8bit_cte;
- if (pp->fmt == CMIT_FMT_USERFORMAT) {
+ if (pp->fmt == CMIT_FMT_USERFORMAT ||
+ pp->fmt == CMIT_FMT_LUA) {
format_commit_message(commit, user_format, sb, pp);
return;
}
--
1.7.12.1.10.g6537447
next prev parent reply other threads:[~2012-09-25 0:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-25 0:23 [RFC/PATCH 0/3] git log --pretty=lua Jeff King
2012-09-25 0:24 ` [PATCH 1/3] pretty: make some commit-parsing helpers more public Jeff King
2012-09-25 0:25 ` [PATCH 2/3] add basic lua infrastructure Jeff King
2012-09-25 1:55 ` Nguyen Thai Ngoc Duy
2012-09-25 4:53 ` Jeff King
2012-09-25 3:21 ` Robin H. Johnson
2012-09-25 3:42 ` Jeff King
2012-09-25 21:18 ` Junio C Hamano
2012-09-25 0:25 ` Jeff King [this message]
2012-10-06 17:33 ` [PATCH 3/3] add a "lua" pretty format Jeff King
2012-09-25 11:22 ` [RFC/PATCH 0/3] git log --pretty=lua Nguyen Thai Ngoc Duy
2012-09-25 13:49 ` Stephen Bash
2012-09-25 15:19 ` Matthieu Moy
2012-09-25 16:40 ` Junio C Hamano
2012-09-30 4:31 ` Nguyen Thai Ngoc Duy
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=20120925002539.GC19605@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/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).