Merge branch 'en/rerere-multi-stage-1-fix'
[gitweb.git] / builtin / am.c
index 6273ea5195bb7f7f2296155753c5e7982d533d66..5e643e2a3e3d70d9c674d3edab2eb1f2f08f3392 100644 (file)
@@ -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.
@@ -1243,6 +1244,10 @@ static int parse_mail(struct am_state *state, const char *mail)
        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)) {
@@ -1400,9 +1405,10 @@ static void write_index_patch(const struct am_state *state)
        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);
@@ -1462,7 +1468,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
        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");
@@ -1596,6 +1602,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
        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;
@@ -1631,7 +1638,8 @@ static void do_commit(const struct am_state *state)
 
        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"));
@@ -1763,7 +1771,7 @@ static void am_run(struct am_state *state, int resume)
 
        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);
        }
@@ -1820,7 +1828,8 @@ static void am_run(struct am_state *state, int resume)
                         * 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;
                        }
@@ -1874,7 +1883,7 @@ static void am_resolve(struct am_state *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."));
@@ -2073,7 +2082,7 @@ static int safe_to_abort(const struct am_state *state)
        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"