diff options
Diffstat (limited to 'pretty.c')
-rw-r--r-- | pretty.c | 51 |
1 files changed, 20 insertions, 31 deletions
@@ -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); @@ -65,7 +70,9 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c commit_format->name = xstrdup(name); commit_format->format = CMIT_FMT_USERFORMAT; - git_config_string(&fmt, var, value); + if (git_config_string(&fmt, var, value)) + return -1; + if (starts_with(fmt, "format:") || starts_with(fmt, "tformat:")) { commit_format->is_tformat = fmt[0] == 't'; fmt = strchr(fmt, ':') + 1; @@ -146,7 +153,7 @@ void get_commit_format(const char *arg, struct rev_info *rev) struct cmt_fmt_map *commit_format; rev->use_terminator = 0; - if (!arg || !*arg) { + if (!arg) { rev->commit_format = CMIT_FMT_DEFAULT; return; } @@ -155,7 +162,7 @@ void get_commit_format(const char *arg, struct rev_info *rev) return; } - if (strchr(arg, '%')) { + if (!*arg || strchr(arg, '%')) { save_user_format(rev, arg, 1); return; } @@ -547,31 +554,11 @@ static void add_merge_info(const struct pretty_print_context *pp, strbuf_addch(sb, '\n'); } -static char *get_header(const struct commit *commit, const char *msg, - const char *key) +static char *get_header(const char *msg, const char *key) { - int key_len = strlen(key); - const char *line = msg; - - while (line) { - const char *eol = strchrnul(line, '\n'), *next; - - if (line == eol) - return NULL; - if (!*eol) { - warning("malformed commit (header is missing newline): %s", - sha1_to_hex(commit->object.sha1)); - next = NULL; - } else - next = eol + 1; - if (eol - line > key_len && - !strncmp(line, key, key_len) && - line[key_len] == ' ') { - return xmemdupz(line + key_len + 1, eol - line - key_len - 1); - } - line = next; - } - return NULL; + size_t len; + const char *v = find_commit_header(msg, key, &len); + return v ? xmemdupz(v, len) : NULL; } static char *replace_encoding_header(char *buf, const char *encoding) @@ -617,11 +604,10 @@ const char *logmsg_reencode(const struct commit *commit, if (!output_encoding || !*output_encoding) { if (commit_encoding) - *commit_encoding = - get_header(commit, msg, "encoding"); + *commit_encoding = get_header(msg, "encoding"); return msg; } - encoding = get_header(commit, msg, "encoding"); + encoding = get_header(msg, "encoding"); if (commit_encoding) *commit_encoding = encoding; use_encoding = encoding ? encoding : utf8; @@ -731,9 +717,12 @@ static size_t format_person_part(struct strbuf *sb, char part, case 'r': /* date, relative */ strbuf_addstr(sb, show_ident_date(&s, DATE_RELATIVE)); return placeholder_len; - case 'i': /* date, ISO 8601 */ + case 'i': /* date, ISO 8601-like */ strbuf_addstr(sb, show_ident_date(&s, DATE_ISO8601)); return placeholder_len; + case 'I': /* date, ISO 8601 strict */ + strbuf_addstr(sb, show_ident_date(&s, DATE_ISO8601_STRICT)); + return placeholder_len; } skip: |