From b9c7d6e4330e3dcdb3b3e5f013e5667e47555c95 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 29 Jul 2014 13:56:48 -0400 Subject: pretty: make empty userformats truly empty 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 Signed-off-by: Junio C Hamano --- pretty.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index f97a762515..31fc76b2fd 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); -- cgit v1.2.1