Merge branch 'rs/mailinfo-format-flowed'
authorJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:53:57 +0000 (13:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:53:57 +0000 (13:53 -0700)
"git mailinfo" used in "git am" learned to make a best-effort
recovery of a patch corrupted by MUA that sends text/plain with
format=flawed option.

* rs/mailinfo-format-flowed:
mailinfo: support format=flowed

1  2 
builtin/am.c
mailinfo.h
diff --combined builtin/am.c
index 162a048bf7a6399b3ab1b5a33045ba726803ff0e,30c87c195372f1987e1db9fe7cca65da32599224..5e643e2a3e3d70d9c674d3edab2eb1f2f08f3392
@@@ -32,7 -32,6 +32,7 @@@
  #include "apply.h"
  #include "string-list.h"
  #include "packfile.h"
 +#include "repository.h"
  
  /**
   * Returns 1 if the file is empty or does not exist, 0 otherwise.
@@@ -1244,6 -1243,10 +1244,10 @@@ static int parse_mail(struct am_state *
        fclose(mi.input);
        fclose(mi.output);
  
+       if (mi.format_flowed)
+               warning(_("Patch sent with format=flowed; "
+                         "space at the end of lines might be lost."));
        /* Extract message and author information */
        fp = xfopen(am_path(state, "info"), "r");
        while (!strbuf_getline_lf(&sb, fp)) {
@@@ -1401,10 -1404,9 +1405,10 @@@ static void write_index_patch(const str
        FILE *fp;
  
        if (!get_oid_tree("HEAD", &head))
 -              tree = lookup_tree(&head);
 +              tree = lookup_tree(the_repository, &head);
        else
 -              tree = lookup_tree(the_hash_algo->empty_tree);
 +              tree = lookup_tree(the_repository,
 +                                 the_repository->hash_algo->empty_tree);
  
        fp = xfopen(am_path(state, "patch"), "w");
        init_revisions(&rev_info, NULL);
@@@ -1464,7 -1466,7 +1468,7 @@@ static int run_apply(const struct am_st
        int force_apply = 0;
        int options = 0;
  
 -      if (init_apply_state(&apply_state, NULL))
 +      if (init_apply_state(&apply_state, the_repository, NULL))
                BUG("init_apply_state() failed");
  
        argv_array_push(&apply_opts, "apply");
@@@ -1598,7 -1600,6 +1602,7 @@@ static int fall_back_threeway(const str
        o.branch1 = "HEAD";
        their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
        o.branch2 = their_tree_name;
 +      o.detect_directory_renames = 0;
  
        if (state->quiet)
                o.verbosity = 0;
@@@ -1634,8 -1635,7 +1638,8 @@@ static void do_commit(const struct am_s
  
        if (!get_oid_commit("HEAD", &parent)) {
                old_oid = &parent;
 -              commit_list_insert(lookup_commit(&parent), &parents);
 +              commit_list_insert(lookup_commit(the_repository, &parent),
 +                                 &parents);
        } else {
                old_oid = NULL;
                say(state, stderr, _("applying to an empty history"));
@@@ -1767,7 -1767,7 +1771,7 @@@ static void am_run(struct am_state *sta
  
        refresh_and_write_cache();
  
 -      if (index_has_changes(&sb)) {
 +      if (index_has_changes(&the_index, NULL, &sb)) {
                write_state_bool(state, "dirtyindex", 1);
                die(_("Dirty index: cannot apply patches (dirty: %s)"), sb.buf);
        }
                         * Applying the patch to an earlier tree and merging
                         * the result may have produced the same tree as ours.
                         */
 -                      if (!apply_status && !index_has_changes(NULL)) {
 +                      if (!apply_status &&
 +                          !index_has_changes(&the_index, NULL, NULL)) {
                                say(state, stdout, _("No changes -- Patch already applied."));
                                goto next;
                        }
                }
  
                if (apply_status) {
 -                      int advice_amworkdir = 1;
 -
                        printf_ln(_("Patch failed at %s %.*s"), msgnum(state),
                                linelen(state->msg), state->msg);
  
 -                      git_config_get_bool("advice.amworkdir", &advice_amworkdir);
 -
                        if (advice_amworkdir)
 -                              printf_ln(_("Use 'git am --show-current-patch' to see the failed patch"));
 +                              advise(_("Use 'git am --show-current-patch' to see the failed patch"));
  
                        die_user_resolve(state);
                }
@@@ -1879,7 -1882,7 +1883,7 @@@ static void am_resolve(struct am_state 
  
        say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
  
 -      if (!index_has_changes(NULL)) {
 +      if (!index_has_changes(&the_index, NULL, NULL)) {
                printf_ln(_("No changes - did you forget to use 'git add'?\n"
                        "If there is nothing left to stage, chances are that something else\n"
                        "already introduced the same changes; you might want to skip this patch."));
@@@ -2078,7 -2081,7 +2082,7 @@@ static int safe_to_abort(const struct a
        if (get_oid("HEAD", &head))
                oidclr(&head);
  
 -      if (!oidcmp(&head, &abort_safety))
 +      if (oideq(&head, &abort_safety))
                return 1;
  
        warning(_("You seem to have moved HEAD since the last 'am' failure.\n"
diff --combined mailinfo.h
index 766c03dd1d29d00beb75b7553fc6717e24978384,67af28dd9f9cb41bdc8e7f6db97638d2573bf995..6830e1e6259bb050cf2af9c2e203c8aa52037da1
@@@ -1,8 -1,6 +1,8 @@@
  #ifndef MAILINFO_H
  #define MAILINFO_H
  
 +#include "strbuf.h"
 +
  #define MAX_BOUNDARIES 5
  
  struct mailinfo {
@@@ -22,6 -20,8 +22,8 @@@
        struct strbuf *content[MAX_BOUNDARIES];
        struct strbuf **content_top;
        struct strbuf charset;
+       unsigned int format_flowed:1;
+       unsigned int delsp:1;
        char *message_id;
        enum  {
                TE_DONTCARE, TE_QP, TE_BASE64