rev-parse: add --shared-index-path to get shared index path
[gitweb.git] / builtin / mailinfo.c
index b691b771587ac676b23c40f8d9090a3750eaa43f..2c3cd8eab7073669001ad605020577279ba7a07d 100644 (file)
@@ -19,9 +19,6 @@ static struct strbuf email = STRBUF_INIT;
 static enum  {
        TE_DONTCARE, TE_QP, TE_BASE64
 } transfer_encoding;
-static enum  {
-       TYPE_TEXT, TYPE_OTHER
-} message_type;
 
 static struct strbuf charset = STRBUF_INIT;
 static int patch_lines;
@@ -160,10 +157,9 @@ static int slurp_attr(const char *line, const char *name, struct strbuf *attr)
        const char *ends, *ap = strcasestr(line, name);
        size_t sz;
 
-       if (!ap) {
-               strbuf_setlen(attr, 0);
+       strbuf_setlen(attr, 0);
+       if (!ap)
                return 0;
-       }
        ap += strlen(name);
        if (*ap == '"') {
                ap++;
@@ -185,8 +181,6 @@ static void handle_content_type(struct strbuf *line)
        struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
        strbuf_init(boundary, line->len);
 
-       if (!strcasestr(line->buf, "text/"))
-                message_type = TYPE_OTHER;
        if (slurp_attr(line->buf, "boundary=", boundary)) {
                strbuf_insert(boundary, 0, "--", 2);
                if (++content_top > &content[MAX_BOUNDARIES]) {
@@ -334,11 +328,11 @@ static int check_header(const struct strbuf *line,
        }
 
        /* for inbody stuff */
-       if (!prefixcmp(line->buf, ">From") && isspace(line->buf[5])) {
+       if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
                ret = 1; /* Should this return 0? */
                goto check_header_out;
        }
-       if (!prefixcmp(line->buf, "[PATCH]") && isspace(line->buf[7])) {
+       if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
                for (i = 0; header[i]; i++) {
                        if (!memcmp("Subject", header[i], 7)) {
                                handle_header(&hdr_data[i], line);
@@ -367,7 +361,7 @@ static int is_rfc2822_header(const struct strbuf *line)
        char *cp = line->buf;
 
        /* Count mbox From headers as headers */
-       if (!prefixcmp(cp, "From ") || !prefixcmp(cp, ">From "))
+       if (starts_with(cp, "From ") || starts_with(cp, ">From "))
                return 1;
 
        while ((ch = *cp++)) {
@@ -489,7 +483,8 @@ static void convert_to_utf8(struct strbuf *line, const char *charset)
 
        if (!charset || !*charset)
                return;
-       if (!strcasecmp(metainfo_charset, charset))
+
+       if (same_encoding(metainfo_charset, charset))
                return;
        out = reencode_string(line->buf, metainfo_charset, charset);
        if (!out)
@@ -658,7 +653,6 @@ static int handle_boundary(void)
        /* set some defaults */
        transfer_encoding = TE_DONTCARE;
        strbuf_reset(&charset);
-       message_type = TYPE_TEXT;
 
        /* slurp in this section's info */
        while (read_one_header_line(&line, fin))
@@ -677,11 +671,11 @@ static inline int patchbreak(const struct strbuf *line)
        size_t i;
 
        /* Beginning of a "diff -" header? */
-       if (!prefixcmp(line->buf, "diff -"))
+       if (starts_with(line->buf, "diff -"))
                return 1;
 
        /* CVS "Index: " line? */
-       if (!prefixcmp(line->buf, "Index: "))
+       if (starts_with(line->buf, "Index: "))
                return 1;
 
        /*
@@ -691,7 +685,7 @@ static inline int patchbreak(const struct strbuf *line)
        if (line->len < 4)
                return 0;
 
-       if (!prefixcmp(line->buf, "---")) {
+       if (starts_with(line->buf, "---")) {
                /* space followed by a filename? */
                if (line->buf[3] == ' ' && !isspace(line->buf[4]))
                        return 1;
@@ -872,11 +866,6 @@ static void handle_body(void)
                        strbuf_insert(&line, 0, prev.buf, prev.len);
                        strbuf_reset(&prev);
 
-                       /* binary data most likely doesn't have newlines */
-                       if (message_type != TYPE_TEXT) {
-                               handle_filter(&line);
-                               break;
-                       }
                        /*
                         * This is a decoded line that may contain
                         * multiple new lines.  Pass only one chunk
@@ -997,7 +986,7 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
 
 static int git_mailinfo_config(const char *var, const char *value, void *unused)
 {
-       if (prefixcmp(var, "mailinfo."))
+       if (!starts_with(var, "mailinfo."))
                return git_default_config(var, value, unused);
        if (!strcmp(var, "mailinfo.scissors")) {
                use_scissors = git_config_bool(var, value);
@@ -1031,7 +1020,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
                        metainfo_charset = def_charset;
                else if (!strcmp(argv[1], "-n"))
                        metainfo_charset = NULL;
-               else if (!prefixcmp(argv[1], "--encoding="))
+               else if (starts_with(argv[1], "--encoding="))
                        metainfo_charset = argv[1] + 11;
                else if (!strcmp(argv[1], "--scissors"))
                        use_scissors = 1;