Merge branch 'rs/commit-pptr-simplify' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 21:27:59 +0000 (13:27 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 21:27:59 +0000 (13:27 -0800)
Code simplification.

* rs/commit-pptr-simplify:
commit: simplify building parents list

1  2 
builtin/commit.c
diff --combined builtin/commit.c
index 7a1ade0d2771cdbd21524381fae0c43a9d0c20cd,f6d6c4759da0f0b96ad2a2882cbfa7715a9f888a..63a8424c5a5342ae52f1cb9f463e260328b5bec5
@@@ -92,9 -92,8 +92,9 @@@ N_("If you wish to skip this commit, us
  "Then \"git cherry-pick --continue\" will resume cherry-picking\n"
  "the remaining commits.\n");
  
 +static GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
 +
  static const char *use_message_buffer;
 -static const char commit_editmsg[] = "COMMIT_EDITMSG";
  static struct lock_file index_lock; /* real index */
  static struct lock_file false_lock; /* used only for partial commits */
  static enum {
@@@ -115,7 -114,6 +115,7 @@@ static char *fixup_message, *squash_mes
  static int all, also, interactive, patch_interactive, only, amend, signoff;
  static int edit_flag = -1; /* unspecified */
  static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
 +static int config_commit_verbose = -1; /* unspecified */
  static int no_post_rewrite, allow_empty_message;
  static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
  static char *sign_commit;
@@@ -188,7 -186,6 +188,7 @@@ static void status_init_config(struct w
        gitmodules_config();
        git_config(fn, s);
        determine_whence(s);
 +      init_diff_ui_defaults();
        s->hints = advice_status_hints; /* must come after git_config() */
  }
  
@@@ -715,7 -712,7 +715,7 @@@ static int prepare_to_commit(const cha
                char *buffer;
                buffer = strstr(use_message_buffer, "\n\n");
                if (buffer)
 -                      strbuf_addstr(&sb, buffer + 2);
 +                      strbuf_addstr(&sb, skip_blank_lines(buffer + 2));
                hook_arg1 = "commit";
                hook_arg2 = use_message;
        } else if (fixup_message) {
                hook_arg2 = "";
        }
  
 -      s->fp = fopen_for_writing(git_path(commit_editmsg));
 +      s->fp = fopen_for_writing(git_path_commit_editmsg());
        if (s->fp == NULL)
 -              die_errno(_("could not open '%s'"), git_path(commit_editmsg));
 +              die_errno(_("could not open '%s'"), git_path_commit_editmsg());
  
        /* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
        old_display_comment_prefix = s->display_comment_prefix;
        }
  
        if (run_commit_hook(use_editor, index_file, "prepare-commit-msg",
 -                          git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
 +                          git_path_commit_editmsg(), hook_arg1, hook_arg2, NULL))
                return 0;
  
        if (use_editor) {
                const char *env[2] = { NULL };
                env[0] =  index;
                snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
 -              if (launch_editor(git_path(commit_editmsg), NULL, env)) {
 +              if (launch_editor(git_path_commit_editmsg(), NULL, env)) {
                        fprintf(stderr,
                        _("Please supply the message using either -m or -F option.\n"));
                        exit(1);
        }
  
        if (!no_verify &&
 -          run_commit_hook(use_editor, index_file, "commit-msg", git_path(commit_editmsg), NULL)) {
 +          run_commit_hook(use_editor, index_file, "commit-msg", git_path_commit_editmsg(), NULL)) {
                return 0;
        }
  
@@@ -1517,11 -1514,6 +1517,11 @@@ static int git_commit_config(const cha
                sign_commit = git_config_bool(k, v) ? "" : NULL;
                return 0;
        }
 +      if (!strcmp(k, "commit.verbose")) {
 +              int is_bool;
 +              config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
 +              return 0;
 +      }
  
        status = git_gpg_config(k, v, NULL);
        if (status)
@@@ -1617,7 -1609,7 +1617,7 @@@ int cmd_commit(int argc, const char **a
                OPT_BOOL(0, "interactive", &interactive, N_("interactively add files")),
                OPT_BOOL('p', "patch", &patch_interactive, N_("interactively add changes")),
                OPT_BOOL('o', "only", &only, N_("commit only specified files")),
 -              OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit hook")),
 +              OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit and commit-msg hooks")),
                OPT_BOOL(0, "dry-run", &dry_run, N_("show what would be committed")),
                OPT_SET_INT(0, "short", &status_format, N_("show status concisely"),
                            STATUS_FORMAT_SHORT),
        const char *index_file, *reflog_msg;
        char *nl;
        unsigned char sha1[20];
-       struct commit_list *parents = NULL, **pptr = &parents;
+       struct commit_list *parents = NULL;
        struct stat statbuf;
        struct commit *current_head = NULL;
        struct commit_extra_header *extra = NULL;
                if (parse_commit(current_head))
                        die(_("could not parse HEAD commit"));
        }
 +      verbose = -1; /* unspecified */
        argc = parse_and_validate_options(argc, argv, builtin_commit_options,
                                          builtin_commit_usage,
                                          prefix, current_head, &s);
 +      if (verbose == -1)
 +              verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
 +
        if (dry_run)
                return dry_run_commit(argc, argv, prefix, current_head, &s);
        index_file = prepare_index(argc, argv, prefix, current_head, 0);
                if (!reflog_msg)
                        reflog_msg = "commit (initial)";
        } else if (amend) {
-               struct commit_list *c;
                if (!reflog_msg)
                        reflog_msg = "commit (amend)";
-               for (c = current_head->parents; c; c = c->next)
-                       pptr = &commit_list_insert(c->item, pptr)->next;
+               parents = copy_commit_list(current_head->parents);
        } else if (whence == FROM_MERGE) {
                struct strbuf m = STRBUF_INIT;
                FILE *fp;
                int allow_fast_forward = 1;
+               struct commit_list **pptr = &parents;
  
                if (!reflog_msg)
                        reflog_msg = "commit (merge)";
-               pptr = &commit_list_insert(current_head, pptr)->next;
+               pptr = commit_list_append(current_head, pptr);
                fp = fopen(git_path_merge_head(), "r");
                if (fp == NULL)
                        die_errno(_("could not open '%s' for reading"),
                        parent = get_merge_parent(m.buf);
                        if (!parent)
                                die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
-                       pptr = &commit_list_insert(parent, pptr)->next;
+                       pptr = commit_list_append(parent, pptr);
                }
                fclose(fp);
                strbuf_release(&m);
                        reflog_msg = (whence == FROM_CHERRY_PICK)
                                        ? "commit (cherry-pick)"
                                        : "commit";
-               pptr = &commit_list_insert(current_head, pptr)->next;
+               commit_list_insert(current_head, &parents);
        }
  
        /* Finally, get the commit message */
        strbuf_reset(&sb);
 -      if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
 +      if (strbuf_read_file(&sb, git_path_commit_editmsg(), 0) < 0) {
                int saved_errno = errno;
                rollback_index_files();
                die(_("could not read commit message: %s"), strerror(saved_errno));