Merge branch 'rs/merge-microcleanup' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:03:02 +0000 (17:03 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:03:02 +0000 (17:03 +0900)
Code clean-up.

* rs/merge-microcleanup:
merge: use skip_prefix()

1  2 
builtin/merge.c
diff --combined builtin/merge.c
index 6150571a56f3996986cc204fd79e86260c02bad7,d9db0baaf3c9368a62363fb9c3f4e550e71ce5e3..23c53a3082b26e8f89f8be1f14985acc491d9907
@@@ -7,7 -7,6 +7,7 @@@
   */
  
  #include "cache.h"
 +#include "config.h"
  #include "parse-options.h"
  #include "builtin.h"
  #include "lockfile.h"
@@@ -416,7 -415,7 +416,7 @@@ static void finish(struct commit *head_
                        DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
                opts.detect_rename = DIFF_DETECT_RENAME;
                diff_setup_done(&opts);
 -              diff_tree_sha1(head->hash, new_head->hash, "", &opts);
 +              diff_tree_oid(head, new_head, "", &opts);
                diffcore_std(&opts);
                diff_flush(&opts);
        }
@@@ -537,7 -536,7 +537,7 @@@ static void parse_branch_merge_options(
                die(_("Bad branch.%s.mergeoptions string: %s"), branch,
                    split_cmdline_strerror(argc));
        REALLOC_ARRAY(argv, argc + 2);
 -      memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
 +      MOVE_ARRAY(argv + 1, argv, argc + 1);
        argc++;
        argv[0] = "branch.*.mergeoptions";
        parse_options(argc, argv, NULL, builtin_merge_options,
@@@ -606,13 -605,13 +606,13 @@@ static int read_tree_trivial(struct obj
        opts.verbose_update = 1;
        opts.trivial_merges_only = 1;
        opts.merge = 1;
 -      trees[nr_trees] = parse_tree_indirect(common->hash);
 +      trees[nr_trees] = parse_tree_indirect(common);
        if (!trees[nr_trees++])
                return -1;
 -      trees[nr_trees] = parse_tree_indirect(head->hash);
 +      trees[nr_trees] = parse_tree_indirect(head);
        if (!trees[nr_trees++])
                return -1;
 -      trees[nr_trees] = parse_tree_indirect(one->hash);
 +      trees[nr_trees] = parse_tree_indirect(one);
        if (!trees[nr_trees++])
                return -1;
        opts.fn = threeway_merge;
@@@ -756,17 -755,13 +756,17 @@@ N_("Please enter a commit message to ex
     "Lines starting with '%c' will be ignored, and an empty message aborts\n"
     "the commit.\n");
  
 +static void write_merge_heads(struct commit_list *);
  static void prepare_to_commit(struct commit_list *remoteheads)
  {
        struct strbuf msg = STRBUF_INIT;
        strbuf_addbuf(&msg, &merge_msg);
        strbuf_addch(&msg, '\n');
 +      if (squash)
 +              BUG("the control must not reach here under --squash");
        if (0 < option_edit)
                strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
 +      write_merge_heads(remoteheads);
        write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
        if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
                            git_path_merge_msg(), "merge", NULL))
@@@ -844,7 -839,9 +844,7 @@@ static int suggest_conflicts(void
        struct strbuf msgbuf = STRBUF_INIT;
  
        filename = git_path_merge_msg();
 -      fp = fopen(filename, "a");
 -      if (!fp)
 -              die_errno(_("Could not open '%s' for writing"), filename);
 +      fp = xfopen(filename, "a");
  
        append_conflicts_hint(&msgbuf);
        fputs(msgbuf.buf, fp);
@@@ -908,7 -905,7 +908,7 @@@ static int setup_with_upstream(const ch
        return i;
  }
  
 -static void write_merge_state(struct commit_list *remoteheads)
 +static void write_merge_heads(struct commit_list *remoteheads)
  {
        struct commit_list *j;
        struct strbuf buf = STRBUF_INIT;
                strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
        }
        write_file_buf(git_path_merge_head(), buf.buf, buf.len);
 -      strbuf_addch(&merge_msg, '\n');
 -      write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
  
        strbuf_reset(&buf);
        if (fast_forward == FF_NO)
        write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
  }
  
 +static void write_merge_state(struct commit_list *remoteheads)
 +{
 +      write_merge_heads(remoteheads);
 +      strbuf_addch(&merge_msg, '\n');
 +      write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
 +}
 +
  static int default_edit_option(void)
  {
        static const char name[] = "GIT_MERGE_AUTOEDIT";
@@@ -1126,12 -1118,12 +1126,12 @@@ int cmd_merge(int argc, const char **ar
         * current branch.
         */
        branch = branch_to_free = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
-       if (branch && starts_with(branch, "refs/heads/"))
-               branch += 11;
+       if (branch)
+               skip_prefix(branch, "refs/heads/", &branch);
        if (!branch || is_null_oid(&head_oid))
                head_commit = NULL;
        else
 -              head_commit = lookup_commit_or_die(head_oid.hash, "HEAD");
 +              head_commit = lookup_commit_or_die(&head_oid, "HEAD");
  
        init_diff_ui_defaults();
        git_config(git_merge_config, NULL);
                        goto done;
                }
  
 -              if (checkout_fast_forward(head_commit->object.oid.hash,
 -                                        commit->object.oid.hash,
 +              if (checkout_fast_forward(&head_commit->object.oid,
 +                                        &commit->object.oid,
                                          overwrite_ignore)) {
                        ret = 1;
                        goto done;