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"
This commit is contained in:
@ -1407,7 +1407,8 @@ void diff_tree_combined(const unsigned char *sha1,
|
|||||||
show_log(rev);
|
show_log(rev);
|
||||||
|
|
||||||
if (rev->verbose_header && opt->output_format &&
|
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),
|
printf("%s%c", diff_line_prefix(opt),
|
||||||
opt->line_termination);
|
opt->line_termination);
|
||||||
}
|
}
|
||||||
|
1
commit.h
1
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,
|
extern const char *format_subject(struct strbuf *sb, const char *msg,
|
||||||
const char *line_separator);
|
const char *line_separator);
|
||||||
extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
|
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,
|
extern void format_commit_message(const struct commit *commit,
|
||||||
const char *format, struct strbuf *sb,
|
const char *format, struct strbuf *sb,
|
||||||
const struct pretty_print_context *context);
|
const struct pretty_print_context *context);
|
||||||
|
@ -649,7 +649,7 @@ void show_log(struct rev_info *opt)
|
|||||||
graph_show_commit_msg(opt->graph, &msgbuf);
|
graph_show_commit_msg(opt->graph, &msgbuf);
|
||||||
else
|
else
|
||||||
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
|
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)
|
if (!opt->missing_newline)
|
||||||
graph_show_padding(opt->graph);
|
graph_show_padding(opt->graph);
|
||||||
putchar(opt->diffopt.line_termination);
|
putchar(opt->diffopt.line_termination);
|
||||||
@ -676,7 +676,8 @@ int log_tree_diff_flush(struct rev_info *opt)
|
|||||||
show_log(opt);
|
show_log(opt);
|
||||||
if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
|
if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
|
||||||
opt->verbose_header &&
|
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),
|
* When showing a verbose header (i.e. log message),
|
||||||
* and not in --pretty=oneline format, we would want
|
* and not in --pretty=oneline format, we would want
|
||||||
|
9
pretty.c
9
pretty.c
@ -24,6 +24,11 @@ static size_t commit_formats_len;
|
|||||||
static size_t commit_formats_alloc;
|
static size_t commit_formats_alloc;
|
||||||
static struct cmt_fmt_map *find_commit_format(const char *sought);
|
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)
|
static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
|
||||||
{
|
{
|
||||||
free(user_format);
|
free(user_format);
|
||||||
@ -146,7 +151,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
|
|||||||
struct cmt_fmt_map *commit_format;
|
struct cmt_fmt_map *commit_format;
|
||||||
|
|
||||||
rev->use_terminator = 0;
|
rev->use_terminator = 0;
|
||||||
if (!arg || !*arg) {
|
if (!arg) {
|
||||||
rev->commit_format = CMIT_FMT_DEFAULT;
|
rev->commit_format = CMIT_FMT_DEFAULT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -155,7 +160,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strchr(arg, '%')) {
|
if (!*arg || strchr(arg, '%')) {
|
||||||
save_user_format(rev, arg, 1);
|
save_user_format(rev, arg, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1825,7 +1825,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
|
|||||||
} else if (!strcmp(arg, "--pretty")) {
|
} else if (!strcmp(arg, "--pretty")) {
|
||||||
revs->verbose_header = 1;
|
revs->verbose_header = 1;
|
||||||
revs->pretty_given = 1;
|
revs->pretty_given = 1;
|
||||||
get_commit_format(arg+8, revs);
|
get_commit_format(NULL, revs);
|
||||||
} else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
|
} else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
|
||||||
/*
|
/*
|
||||||
* Detached form ("--pretty X" as opposed to "--pretty=X")
|
* Detached form ("--pretty X" as opposed to "--pretty=X")
|
||||||
|
Reference in New Issue
Block a user