From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH v2 3/6] pretty: make empty userformats truly empty
Date: Tue, 29 Jul 2014 13:56:48 -0400 [thread overview]
Message-ID: <20140729175648.GC31181@peff.net> (raw)
In-Reply-To: <20140729175300.GA21536@peff.net>
If the user provides an empty format with "--format=", we
end up putting in extra whitespace that the user cannot
prevent. This comes from two places:
1. If the format is missing a terminating newline, we add
one automatically. This makes sense for --format=%h, but
not for a truly empty format.
2. We add an extra newline between the pretty-printed
format and a diff or diffstat. If the format is empty,
there's no point in doing so if there's nothing to
separate.
With this patch, one can get a diff with no other cruft out
of "diff-tree --format= $commit".
Signed-off-by: Jeff King <peff@peff.net>
---
I assume nobody really cared about including that extra whitespace with
a blank format (I have come across this literally dozens of times in the
past few years, and everytime wanted the behavior that this patch gives,
not the other). But if somebody is depending on it, our alternate route
would be to introduce a new CMIT_FMT_NONE. I started on that, but it
really does end up hitting all of the same weird special-cases that that
CMIT_FMT_USERFORMAT does. If we can do it this way, I think the code is
a lot cleaner.
combine-diff.c | 3 ++-
commit.h | 1 +
log-tree.c | 5 +++--
pretty.c | 5 +++++
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/combine-diff.c b/combine-diff.c
index f9975d2..1a1e659 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1397,7 +1397,8 @@ void diff_tree_combined(const unsigned char *sha1,
show_log(rev);
if (rev->verbose_header && opt->output_format &&
- opt->output_format != DIFF_FORMAT_NO_OUTPUT)
+ opt->output_format != DIFF_FORMAT_NO_OUTPUT &&
+ !commit_format_is_empty(rev->commit_format))
printf("%s%c", diff_line_prefix(opt),
opt->line_termination);
}
diff --git a/commit.h b/commit.h
index a8cbf52..aa8c3ca 100644
--- a/commit.h
+++ b/commit.h
@@ -159,6 +159,7 @@ extern void get_commit_format(const char *arg, struct rev_info *);
extern const char *format_subject(struct strbuf *sb, const char *msg,
const char *line_separator);
extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
+extern int commit_format_is_empty(enum cmit_fmt);
extern void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *context);
diff --git a/log-tree.c b/log-tree.c
index 0c53dc1..95e9b1d 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -649,7 +649,7 @@ void show_log(struct rev_info *opt)
graph_show_commit_msg(opt->graph, &msgbuf);
else
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
- if (opt->use_terminator) {
+ if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) {
if (!opt->missing_newline)
graph_show_padding(opt->graph);
putchar(opt->diffopt.line_termination);
@@ -676,7 +676,8 @@ int log_tree_diff_flush(struct rev_info *opt)
show_log(opt);
if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
opt->verbose_header &&
- opt->commit_format != CMIT_FMT_ONELINE) {
+ opt->commit_format != CMIT_FMT_ONELINE &&
+ !commit_format_is_empty(opt->commit_format)) {
/*
* When showing a verbose header (i.e. log message),
* and not in --pretty=oneline format, we would want
diff --git a/pretty.c b/pretty.c
index f97a762..31fc76b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -24,6 +24,11 @@ static size_t commit_formats_len;
static size_t commit_formats_alloc;
static struct cmt_fmt_map *find_commit_format(const char *sought);
+int commit_format_is_empty(enum cmit_fmt fmt)
+{
+ return fmt == CMIT_FMT_USERFORMAT && !*user_format;
+}
+
static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
{
free(user_format);
--
2.1.0.rc0.286.g5c67d74
next prev parent reply other threads:[~2014-07-29 17:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 11:53 [PATCH 0/2] improving "git stash list -p" Jeff King
2014-07-29 12:00 ` [PATCH 1/2] add --simplify-combined-diff option Jeff King
2014-07-29 13:00 ` Jeff King
2014-07-29 12:03 ` [PATCH 2/2] stash: default listing to "--cc --simplify-combined-diff" Jeff King
2014-07-29 12:07 ` [RFC/PATCH 3/2] stash: show combined diff with "stash show" Jeff King
2014-07-29 18:13 ` Junio C Hamano
2014-07-31 0:17 ` Jeff King
2014-07-31 0:28 ` Junio C Hamano
2014-07-29 17:53 ` [PATCH v2 0/6] improving "git stash list -p" Jeff King
2014-07-29 17:53 ` [PATCH v2 1/6] revision: drop useless string offset when parsing "--pretty" Jeff King
2014-07-29 17:54 ` [PATCH v2 2/6] pretty: treat "--format=" as an empty userformat Jeff King
2014-07-29 17:56 ` Jeff King [this message]
2014-07-29 17:57 ` [PATCH v2 4/6] add --simplify-combined-diff option Jeff King
2014-07-29 20:02 ` Junio C Hamano
2014-07-29 17:57 ` [PATCH v2 5/6] stash: default listing to "--cc --simplify-combined-diff" Jeff King
2014-07-29 18:58 ` Junio C Hamano
2014-07-30 19:43 ` Junio C Hamano
2014-07-31 0:09 ` Jeff King
2014-08-12 23:30 ` Keller, Jacob E
2014-07-29 17:58 ` [PATCH v2 6/6] stash: show combined diff with "stash show" Jeff King
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=20140729175648.GC31181@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.