Skip to content

Commit 44ceb79

Browse files
committed
Merge branch 'jk/pretty-empty-format'
"git log --pretty/format=" with an empty format string did not mean the more obvious "No output whatsoever" but "Use default format", which was counterintuitive. * jk/pretty-empty-format: pretty: make empty userformats truly empty pretty: treat "--format=" as an empty userformat revision: drop useless string offset when parsing "--pretty"
2 parents 56f214e + b9c7d6e commit 44ceb79

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

combine-diff.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,8 @@ void diff_tree_combined(const unsigned char *sha1,
14071407
show_log(rev);
14081408

14091409
if (rev->verbose_header && opt->output_format &&
1410-
opt->output_format != DIFF_FORMAT_NO_OUTPUT)
1410+
opt->output_format != DIFF_FORMAT_NO_OUTPUT &&
1411+
!commit_format_is_empty(rev->commit_format))
14111412
printf("%s%c", diff_line_prefix(opt),
14121413
opt->line_termination);
14131414
}

commit.h

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ extern void get_commit_format(const char *arg, struct rev_info *);
159159
extern const char *format_subject(struct strbuf *sb, const char *msg,
160160
const char *line_separator);
161161
extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
162+
extern int commit_format_is_empty(enum cmit_fmt);
162163
extern void format_commit_message(const struct commit *commit,
163164
const char *format, struct strbuf *sb,
164165
const struct pretty_print_context *context);

log-tree.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ void show_log(struct rev_info *opt)
649649
graph_show_commit_msg(opt->graph, &msgbuf);
650650
else
651651
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
652-
if (opt->use_terminator) {
652+
if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) {
653653
if (!opt->missing_newline)
654654
graph_show_padding(opt->graph);
655655
putchar(opt->diffopt.line_termination);
@@ -676,7 +676,8 @@ int log_tree_diff_flush(struct rev_info *opt)
676676
show_log(opt);
677677
if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
678678
opt->verbose_header &&
679-
opt->commit_format != CMIT_FMT_ONELINE) {
679+
opt->commit_format != CMIT_FMT_ONELINE &&
680+
!commit_format_is_empty(opt->commit_format)) {
680681
/*
681682
* When showing a verbose header (i.e. log message),
682683
* and not in --pretty=oneline format, we would want

pretty.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ static size_t commit_formats_len;
2424
static size_t commit_formats_alloc;
2525
static struct cmt_fmt_map *find_commit_format(const char *sought);
2626

27+
int commit_format_is_empty(enum cmit_fmt fmt)
28+
{
29+
return fmt == CMIT_FMT_USERFORMAT && !*user_format;
30+
}
31+
2732
static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
2833
{
2934
free(user_format);
@@ -146,7 +151,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
146151
struct cmt_fmt_map *commit_format;
147152

148153
rev->use_terminator = 0;
149-
if (!arg || !*arg) {
154+
if (!arg) {
150155
rev->commit_format = CMIT_FMT_DEFAULT;
151156
return;
152157
}
@@ -155,7 +160,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
155160
return;
156161
}
157162

158-
if (strchr(arg, '%')) {
163+
if (!*arg || strchr(arg, '%')) {
159164
save_user_format(rev, arg, 1);
160165
return;
161166
}

revision.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
18251825
} else if (!strcmp(arg, "--pretty")) {
18261826
revs->verbose_header = 1;
18271827
revs->pretty_given = 1;
1828-
get_commit_format(arg+8, revs);
1828+
get_commit_format(NULL, revs);
18291829
} else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
18301830
/*
18311831
* Detached form ("--pretty X" as opposed to "--pretty=X")

0 commit comments

Comments
 (0)