apply: make some names more specific
[gitweb.git] / builtin / am.c
index 5fdf5b4c2428b47db9dabf9a41094ec9a4db8964..b77bf11acecd7cd80171c78378154c712415af6f 100644 (file)
@@ -70,7 +70,8 @@ enum patch_format {
        PATCH_FORMAT_MBOX,
        PATCH_FORMAT_STGIT,
        PATCH_FORMAT_STGIT_SERIES,
-       PATCH_FORMAT_HG
+       PATCH_FORMAT_HG,
+       PATCH_FORMAT_MBOXRD
 };
 
 enum keep_type {
@@ -707,7 +708,8 @@ static int detect_patch_format(const char **paths)
  * Splits out individual email patches from `paths`, where each path is either
  * a mbox file or a Maildir. Returns 0 on success, -1 on failure.
  */
-static int split_mail_mbox(struct am_state *state, const char **paths, int keep_cr)
+static int split_mail_mbox(struct am_state *state, const char **paths,
+                               int keep_cr, int mboxrd)
 {
        struct child_process cp = CHILD_PROCESS_INIT;
        struct strbuf last = STRBUF_INIT;
@@ -719,6 +721,8 @@ static int split_mail_mbox(struct am_state *state, const char **paths, int keep_
        argv_array_push(&cp.args, "-b");
        if (keep_cr)
                argv_array_push(&cp.args, "--keep-cr");
+       if (mboxrd)
+               argv_array_push(&cp.args, "--mboxrd");
        argv_array_push(&cp.args, "--");
        argv_array_pushv(&cp.args, paths);
 
@@ -960,13 +964,15 @@ static int split_mail(struct am_state *state, enum patch_format patch_format,
 
        switch (patch_format) {
        case PATCH_FORMAT_MBOX:
-               return split_mail_mbox(state, paths, keep_cr);
+               return split_mail_mbox(state, paths, keep_cr, 0);
        case PATCH_FORMAT_STGIT:
                return split_mail_conv(stgit_patch_to_mail, state, paths, keep_cr);
        case PATCH_FORMAT_STGIT_SERIES:
                return split_mail_stgit_series(state, paths, keep_cr);
        case PATCH_FORMAT_HG:
                return split_mail_conv(hg_patch_to_mail, state, paths, keep_cr);
+       case PATCH_FORMAT_MBOXRD:
+               return split_mail_mbox(state, paths, keep_cr, 1);
        default:
                die("BUG: invalid patch_format");
        }
@@ -1573,14 +1579,14 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f
 }
 
 /**
- * Do the three-way merge using fake ancestor, his tree constructed
+ * Do the three-way merge using fake ancestor, their tree constructed
  * from the fake ancestor and the postimage of the patch, and our
  * state.
  */
 static int run_fallback_merge_recursive(const struct am_state *state,
                                        unsigned char *orig_tree,
                                        unsigned char *our_tree,
-                                       unsigned char *his_tree)
+                                       unsigned char *their_tree)
 {
        struct child_process cp = CHILD_PROCESS_INIT;
        int status;
@@ -1588,7 +1594,7 @@ static int run_fallback_merge_recursive(const struct am_state *state,
        cp.git_cmd = 1;
 
        argv_array_pushf(&cp.env_array, "GITHEAD_%s=%.*s",
-                        sha1_to_hex(his_tree), linelen(state->msg), state->msg);
+                        sha1_to_hex(their_tree), linelen(state->msg), state->msg);
        if (state->quiet)
                argv_array_push(&cp.env_array, "GIT_MERGE_VERBOSITY=0");
 
@@ -1596,7 +1602,7 @@ static int run_fallback_merge_recursive(const struct am_state *state,
        argv_array_push(&cp.args, sha1_to_hex(orig_tree));
        argv_array_push(&cp.args, "--");
        argv_array_push(&cp.args, sha1_to_hex(our_tree));
-       argv_array_push(&cp.args, sha1_to_hex(his_tree));
+       argv_array_push(&cp.args, sha1_to_hex(their_tree));
 
        status = run_command(&cp) ? (-1) : 0;
        discard_cache();
@@ -1609,7 +1615,7 @@ static int run_fallback_merge_recursive(const struct am_state *state,
  */
 static int fall_back_threeway(const struct am_state *state, const char *index_path)
 {
-       unsigned char orig_tree[GIT_SHA1_RAWSZ], his_tree[GIT_SHA1_RAWSZ],
+       unsigned char orig_tree[GIT_SHA1_RAWSZ], their_tree[GIT_SHA1_RAWSZ],
                      our_tree[GIT_SHA1_RAWSZ];
 
        if (get_sha1("HEAD", our_tree) < 0)
@@ -1646,7 +1652,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
                return error(_("Did you hand edit your patch?\n"
                                "It does not apply to blobs recorded in its index."));
 
-       if (write_index_as_tree(his_tree, &the_index, index_path, 0, NULL))
+       if (write_index_as_tree(their_tree, &the_index, index_path, 0, NULL))
                return error("could not write tree");
 
        say(state, stdout, _("Falling back to patching base and 3-way merge..."));
@@ -1656,13 +1662,13 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 
        /*
         * This is not so wrong. Depending on which base we picked, orig_tree
-        * may be wildly different from ours, but his_tree has the same set of
+        * may be wildly different from ours, but their_tree has the same set of
         * wildly different changes in parts the patch did not touch, so
         * recursive ends up canceling them, saying that we reverted all those
         * changes.
         */
 
-       if (run_fallback_merge_recursive(state, orig_tree, our_tree, his_tree)) {
+       if (run_fallback_merge_recursive(state, orig_tree, our_tree, their_tree)) {
                rerere(state->allow_rerere_autoupdate);
                return error(_("Failed to merge in the changes."));
        }
@@ -2196,6 +2202,8 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
                *opt_value = PATCH_FORMAT_STGIT_SERIES;
        else if (!strcmp(arg, "hg"))
                *opt_value = PATCH_FORMAT_HG;
+       else if (!strcmp(arg, "mboxrd"))
+               *opt_value = PATCH_FORMAT_MBOXRD;
        else
                return error(_("Invalid value for --patch-format: %s"), arg);
        return 0;