diff options
Diffstat (limited to 'mailinfo.c')
-rw-r--r-- | mailinfo.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/mailinfo.c b/mailinfo.c index 931505363c..d1f42bd7e3 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1,7 +1,9 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "gettext.h" -#include "hex.h" +#include "hex-ll.h" #include "utf8.h" #include "strbuf.h" #include "mailinfo.h" @@ -58,12 +60,13 @@ static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line) static const char *unquote_comment(struct strbuf *outbuf, const char *in) { - int c; int take_next_literally = 0; + int depth = 1; strbuf_addch(outbuf, '('); - while ((c = *in++) != 0) { + while (*in) { + int c = *in++; if (take_next_literally == 1) { take_next_literally = 0; } else { @@ -72,11 +75,14 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in) take_next_literally = 1; continue; case '(': - in = unquote_comment(outbuf, in); + strbuf_addch(outbuf, '('); + depth++; continue; case ')': strbuf_addch(outbuf, ')'); - return in; + if (!--depth) + return in; + continue; } } @@ -88,10 +94,10 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in) static const char *unquote_quoted_string(struct strbuf *outbuf, const char *in) { - int c; int take_next_literally = 0; - while ((c = *in++) != 0) { + while (*in) { + int c = *in++; if (take_next_literally == 1) { take_next_literally = 0; } else { @@ -342,9 +348,8 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject) strbuf_trim(subject); } -#define MAX_HDR_PARSED 10 -static const char *header[MAX_HDR_PARSED] = { - "From","Subject","Date", +static const char * const header[] = { + "From", "Subject", "Date", }; static inline int skip_header(const struct strbuf *line, const char *hdr, @@ -579,7 +584,7 @@ static int check_header(struct mailinfo *mi, struct strbuf sb = STRBUF_INIT; /* search for the interesting parts */ - for (i = 0; header[i]; i++) { + for (i = 0; i < ARRAY_SIZE(header); i++) { if ((!hdr_data[i] || overwrite) && parse_header(line, header[i], mi, &sb)) { handle_header(&hdr_data[i], &sb); @@ -621,7 +626,7 @@ static int is_inbody_header(const struct mailinfo *mi, { int i; const char *val; - for (i = 0; header[i]; i++) + for (i = 0; i < ARRAY_SIZE(header); i++) if (!mi->s_hdr_data[i] && skip_header(line, header[i], &val)) return 1; return 0; @@ -768,7 +773,7 @@ static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line) return is_format_patch_separator(line->buf + 1, line->len - 1); if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) { int i; - for (i = 0; header[i]; i++) + for (i = 0; i < ARRAY_SIZE(header); i++) if (!strcmp("Subject", header[i])) { handle_header(&mi->s_hdr_data[i], line); return 1; @@ -820,7 +825,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line) * We may have already read "secondary headers"; purge * them to give ourselves a clean restart. */ - for (i = 0; header[i]; i++) { + for (i = 0; i < ARRAY_SIZE(header); i++) { if (mi->s_hdr_data[i]) strbuf_release(mi->s_hdr_data[i]); FREE_AND_NULL(mi->s_hdr_data[i]); @@ -1151,7 +1156,7 @@ static void handle_info(struct mailinfo *mi) struct strbuf *hdr; int i; - for (i = 0; header[i]; i++) { + for (i = 0; i < ARRAY_SIZE(header); i++) { /* only print inbody headers if we output a patch file */ if (mi->patch_lines && mi->s_hdr_data[i]) hdr = mi->s_hdr_data[i]; @@ -1202,8 +1207,8 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch) return -1; } - mi->p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->p_hdr_data))); - mi->s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->s_hdr_data))); + mi->p_hdr_data = xcalloc(ARRAY_SIZE(header), sizeof(*(mi->p_hdr_data))); + mi->s_hdr_data = xcalloc(ARRAY_SIZE(header), sizeof(*(mi->s_hdr_data))); do { peek = fgetc(mi->input); @@ -1253,6 +1258,8 @@ static int git_mailinfo_config(const char *var, const char *value, return 0; } if (!strcmp(var, "mailinfo.quotedcr")) { + if (!value) + return config_error_nonbool(var); if (mailinfo_parse_quoted_cr_action(value, &mi->quoted_cr) != 0) return error(_("bad action '%s' for '%s'"), value, var); return 0; @@ -1284,8 +1291,21 @@ void clear_mailinfo(struct mailinfo *mi) strbuf_release(&mi->inbody_header_accum); free(mi->message_id); - strbuf_list_free(mi->p_hdr_data); - strbuf_list_free(mi->s_hdr_data); + for (size_t i = 0; i < ARRAY_SIZE(header); i++) { + if (!mi->p_hdr_data[i]) + continue; + strbuf_release(mi->p_hdr_data[i]); + free(mi->p_hdr_data[i]); + } + free(mi->p_hdr_data); + + for (size_t i = 0; i < ARRAY_SIZE(header); i++) { + if (!mi->s_hdr_data[i]) + continue; + strbuf_release(mi->s_hdr_data[i]); + free(mi->s_hdr_data[i]); + } + free(mi->s_hdr_data); while (mi->content < mi->content_top) { free(*(mi->content_top)); |