Merge branch 'jc/maint-fmt-merge-msg-no-edit-lose-credit' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 14 Jan 2013 15:33:30 +0000 (07:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jan 2013 15:33:30 +0000 (07:33 -0800)
"git merge --no-edit" computed who were involved in the work done
on the side branch, even though that information is to be discarded
without getting seen in the editor.

* jc/maint-fmt-merge-msg-no-edit-lose-credit:
merge --no-edit: do not credit people involved in the side branch

1  2 
builtin.h
builtin/fmt-merge-msg.c
builtin/merge.c
diff --combined builtin.h
index 3faf9d6691413c006f4c82702aa5e0c5e4bc88a0,3ad8d19bc5e2e87274216c8fadcec4f32bb20483..7e7bbd665a905b0fdf9ce5351f6f09dfd3dd7e8a
+++ b/builtin.h
@@@ -9,18 -9,21 +9,19 @@@
  
  #define DEFAULT_MERGE_LOG_LEN 20
  
 -extern const char git_version_string[];
  extern const char git_usage_string[];
  extern const char git_more_info_string[];
  
  extern void prune_packed_objects(int);
  
  struct fmt_merge_msg_opts {
-       unsigned add_title:1;
+       unsigned add_title:1,
+               credit_people:1;
        int shortlog_len;
  };
  
  extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
                         struct fmt_merge_msg_opts *);
 -extern void commit_notes(struct notes_tree *t, const char *msg);
  
  struct notes_rewrite_cfg {
        struct notes_tree **trees;
        int mode_from_env;
  };
  
 -combine_notes_fn parse_combine_notes_fn(const char *v);
  struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
  int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
                          const unsigned char *from_obj, const unsigned char *to_obj);
  void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
  
 -extern int check_pager_config(const char *cmd);
 -struct diff_options;
 -extern void setup_diff_pager(struct diff_options *);
 -
  extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
  
  extern int cmd_add(int argc, const char **argv, const char *prefix);
@@@ -61,7 -69,6 +62,7 @@@ extern int cmd_commit(int argc, const c
  extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
  extern int cmd_config(int argc, const char **argv, const char *prefix);
  extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
 +extern int cmd_credential(int argc, const char **argv, const char *prefix);
  extern int cmd_describe(int argc, const char **argv, const char *prefix);
  extern int cmd_diff_files(int argc, const char **argv, const char *prefix);
  extern int cmd_diff_index(int argc, const char **argv, const char *prefix);
diff --combined builtin/fmt-merge-msg.c
index e2e27b2c404a1c451a20e396a7aa03dece722dad,dd1f363c5b0ba022ff817841bb75e80c7fa95d38..d9af43c257150c957bf3bc3c3b7a7e43e370174c
@@@ -10,7 -10,7 +10,7 @@@
  #include "gpg-interface.h"
  
  static const char * const fmt_merge_msg_usage[] = {
 -      "git fmt-merge-msg [-m <message>] [--log[=<n>]|--no-log] [--file <file>]",
 +      N_("git fmt-merge-msg [-m <message>] [--log[=<n>]|--no-log] [--file <file>]"),
        NULL
  };
  
@@@ -232,8 -232,9 +232,9 @@@ static void record_person(int which, st
  {
        char *name_buf, *name, *name_end;
        struct string_list_item *elem;
-       const char *field = (which == 'a') ? "\nauthor " : "\ncommitter ";
+       const char *field;
  
+       field = (which == 'a') ? "\nauthor " : "\ncommitter ";
        name = strstr(commit->buffer, field);
        if (!name)
                return;
@@@ -323,7 -324,8 +324,8 @@@ static void add_people_info(struct strb
  static void shortlog(const char *name,
                     struct origin_data *origin_data,
                     struct commit *head,
-                    struct rev_info *rev, int limit,
+                    struct rev_info *rev,
+                    struct fmt_merge_msg_opts *opts,
                     struct strbuf *out)
  {
        int i, count = 0;
        int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
        struct strbuf sb = STRBUF_INIT;
        const unsigned char *sha1 = origin_data->sha1;
+       int limit = opts->shortlog_len;
  
        branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
        if (!branch || branch->type != OBJ_COMMIT)
  
                if (commit->parents && commit->parents->next) {
                        /* do not list a merge but count committer */
-                       record_person('c', &committers, commit);
+                       if (opts->credit_people)
+                               record_person('c', &committers, commit);
                        continue;
                }
-               if (!count)
+               if (!count && opts->credit_people)
                        /* the 'tip' committer */
                        record_person('c', &committers, commit);
-               record_person('a', &authors, commit);
+               if (opts->credit_people)
+                       record_person('a', &authors, commit);
                count++;
                if (subjects.nr > limit)
                        continue;
                        string_list_append(&subjects, strbuf_detach(&sb, NULL));
        }
  
-       add_people_info(out, &authors, &committers);
+       if (opts->credit_people)
+               add_people_info(out, &authors, &committers);
        if (count > limit)
                strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
        else
@@@ -635,7 -641,7 +641,7 @@@ int fmt_merge_msg(struct strbuf *in, st
                for (i = 0; i < origins.nr; i++)
                        shortlog(origins.items[i].string,
                                 origins.items[i].util,
-                                head, &rev, opts->shortlog_len, out);
+                                head, &rev, opts, out);
        }
  
        strbuf_complete_line(out);
@@@ -650,16 -656,16 +656,16 @@@ int cmd_fmt_merge_msg(int argc, const c
        const char *message = NULL;
        int shortlog_len = -1;
        struct option options[] = {
 -              { OPTION_INTEGER, 0, "log", &shortlog_len, "n",
 -                "populate log with at most <n> entries from shortlog",
 +              { OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"),
 +                N_("populate log with at most <n> entries from shortlog"),
                  PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
 -              { OPTION_INTEGER, 0, "summary", &shortlog_len, "n",
 -                "alias for --log (deprecated)",
 +              { OPTION_INTEGER, 0, "summary", &shortlog_len, N_("n"),
 +                N_("alias for --log (deprecated)"),
                  PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL,
                  DEFAULT_MERGE_LOG_LEN },
 -              OPT_STRING('m', "message", &message, "text",
 -                      "use <text> as start of message"),
 -              OPT_FILENAME('F', "file", &inpath, "file to read from"),
 +              OPT_STRING('m', "message", &message, N_("text"),
 +                      N_("use <text> as start of message")),
 +              OPT_FILENAME('F', "file", &inpath, N_("file to read from")),
                OPT_END()
        };
  
  
        memset(&opts, 0, sizeof(opts));
        opts.add_title = !message;
+       opts.credit_people = 1;
        opts.shortlog_len = shortlog_len;
  
        ret = fmt_merge_msg(&input, &output, &opts);
diff --combined builtin/merge.c
index 3a31c4bc259a3169d815b9a3966675d9faab7ab7,c5d35515675fca9a17f2782d08da84ce115834e3..9307e9c726587461d002530938dbf2c0d74d55a1
@@@ -40,9 -40,9 +40,9 @@@ struct strategy 
  };
  
  static const char * const builtin_merge_usage[] = {
 -      "git merge [options] [<commit>...]",
 -      "git merge [options] <msg> HEAD <commit>",
 -      "git merge --abort",
 +      N_("git merge [options] [<commit>...]"),
 +      N_("git merge [options] <msg> HEAD <commit>"),
 +      N_("git merge --abort"),
        NULL
  };
  
@@@ -180,39 -180,39 +180,39 @@@ static int option_parse_n(const struct 
  
  static struct option builtin_merge_options[] = {
        { OPTION_CALLBACK, 'n', NULL, NULL, NULL,
 -              "do not show a diffstat at the end of the merge",
 +              N_("do not show a diffstat at the end of the merge"),
                PARSE_OPT_NOARG, option_parse_n },
        OPT_BOOLEAN(0, "stat", &show_diffstat,
 -              "show a diffstat at the end of the merge"),
 -      OPT_BOOLEAN(0, "summary", &show_diffstat, "(synonym to --stat)"),
 -      { OPTION_INTEGER, 0, "log", &shortlog_len, "n",
 -        "add (at most <n>) entries from shortlog to merge commit message",
 +              N_("show a diffstat at the end of the merge")),
 +      OPT_BOOLEAN(0, "summary", &show_diffstat, N_("(synonym to --stat)")),
 +      { OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"),
 +        N_("add (at most <n>) entries from shortlog to merge commit message"),
          PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
        OPT_BOOLEAN(0, "squash", &squash,
 -              "create a single commit instead of doing a merge"),
 +              N_("create a single commit instead of doing a merge")),
        OPT_BOOLEAN(0, "commit", &option_commit,
 -              "perform a commit if the merge succeeds (default)"),
 +              N_("perform a commit if the merge succeeds (default)")),
        OPT_BOOL('e', "edit", &option_edit,
 -              "edit message before committing"),
 +              N_("edit message before committing")),
        OPT_BOOLEAN(0, "ff", &allow_fast_forward,
 -              "allow fast-forward (default)"),
 +              N_("allow fast-forward (default)")),
        OPT_BOOLEAN(0, "ff-only", &fast_forward_only,
 -              "abort if fast-forward is not possible"),
 +              N_("abort if fast-forward is not possible")),
        OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
 -      OPT_CALLBACK('s', "strategy", &use_strategies, "strategy",
 -              "merge strategy to use", option_parse_strategy),
 -      OPT_CALLBACK('X', "strategy-option", &xopts, "option=value",
 -              "option for selected merge strategy", option_parse_x),
 -      OPT_CALLBACK('m', "message", &merge_msg, "message",
 -              "merge commit message (for a non-fast-forward merge)",
 +      OPT_CALLBACK('s', "strategy", &use_strategies, N_("strategy"),
 +              N_("merge strategy to use"), option_parse_strategy),
 +      OPT_CALLBACK('X', "strategy-option", &xopts, N_("option=value"),
 +              N_("option for selected merge strategy"), option_parse_x),
 +      OPT_CALLBACK('m', "message", &merge_msg, N_("message"),
 +              N_("merge commit message (for a non-fast-forward merge)"),
                option_parse_message),
        OPT__VERBOSITY(&verbosity),
        OPT_BOOLEAN(0, "abort", &abort_current_merge,
 -              "abort the current in-progress merge"),
 -      OPT_SET_INT(0, "progress", &show_progress, "force progress reporting", 1),
 -      { OPTION_STRING, 'S', "gpg-sign", &sign_commit, "key id",
 -        "GPG sign commit", PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 -      OPT_BOOLEAN(0, "overwrite-ignore", &overwrite_ignore, "update ignored files (default)"),
 +              N_("abort the current in-progress merge")),
 +      OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1),
 +      { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key id"),
 +        N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 +      OPT_BOOLEAN(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
        OPT_END()
  };
  
@@@ -628,6 -628,59 +628,6 @@@ static void write_tree_trivial(unsigne
                die(_("git write-tree failed to write a tree"));
  }
  
 -static const char *merge_argument(struct commit *commit)
 -{
 -      if (commit)
 -              return sha1_to_hex(commit->object.sha1);
 -      else
 -              return EMPTY_TREE_SHA1_HEX;
 -}
 -
 -int try_merge_command(const char *strategy, size_t xopts_nr,
 -                    const char **xopts, struct commit_list *common,
 -                    const char *head_arg, struct commit_list *remotes)
 -{
 -      const char **args;
 -      int i = 0, x = 0, ret;
 -      struct commit_list *j;
 -      struct strbuf buf = STRBUF_INIT;
 -
 -      args = xmalloc((4 + xopts_nr + commit_list_count(common) +
 -                      commit_list_count(remotes)) * sizeof(char *));
 -      strbuf_addf(&buf, "merge-%s", strategy);
 -      args[i++] = buf.buf;
 -      for (x = 0; x < xopts_nr; x++) {
 -              char *s = xmalloc(strlen(xopts[x])+2+1);
 -              strcpy(s, "--");
 -              strcpy(s+2, xopts[x]);
 -              args[i++] = s;
 -      }
 -      for (j = common; j; j = j->next)
 -              args[i++] = xstrdup(merge_argument(j->item));
 -      args[i++] = "--";
 -      args[i++] = head_arg;
 -      for (j = remotes; j; j = j->next)
 -              args[i++] = xstrdup(merge_argument(j->item));
 -      args[i] = NULL;
 -      ret = run_command_v_opt(args, RUN_GIT_CMD);
 -      strbuf_release(&buf);
 -      i = 1;
 -      for (x = 0; x < xopts_nr; x++)
 -              free((void *)args[i++]);
 -      for (j = common; j; j = j->next)
 -              free((void *)args[i++]);
 -      i += 2;
 -      for (j = remotes; j; j = j->next)
 -              free((void *)args[i++]);
 -      free(args);
 -      discard_cache();
 -      if (read_cache() < 0)
 -              die(_("failed to read the cache"));
 -      resolve_undo_clear();
 -
 -      return ret;
 -}
 -
  static int try_merge_strategy(const char *strategy, struct commit_list *common,
                              struct commit_list *remoteheads,
                              struct commit *head, const char *head_arg)
@@@ -709,6 -762,56 +709,6 @@@ static int count_unmerged_entries(void
        return ret;
  }
  
 -int checkout_fast_forward(const unsigned char *head, const unsigned char *remote)
 -{
 -      struct tree *trees[MAX_UNPACK_TREES];
 -      struct unpack_trees_options opts;
 -      struct tree_desc t[MAX_UNPACK_TREES];
 -      int i, fd, nr_trees = 0;
 -      struct dir_struct dir;
 -      struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
 -
 -      refresh_cache(REFRESH_QUIET);
 -
 -      fd = hold_locked_index(lock_file, 1);
 -
 -      memset(&trees, 0, sizeof(trees));
 -      memset(&opts, 0, sizeof(opts));
 -      memset(&t, 0, sizeof(t));
 -      if (overwrite_ignore) {
 -              memset(&dir, 0, sizeof(dir));
 -              dir.flags |= DIR_SHOW_IGNORED;
 -              setup_standard_excludes(&dir);
 -              opts.dir = &dir;
 -      }
 -
 -      opts.head_idx = 1;
 -      opts.src_index = &the_index;
 -      opts.dst_index = &the_index;
 -      opts.update = 1;
 -      opts.verbose_update = 1;
 -      opts.merge = 1;
 -      opts.fn = twoway_merge;
 -      setup_unpack_trees_porcelain(&opts, "merge");
 -
 -      trees[nr_trees] = parse_tree_indirect(head);
 -      if (!trees[nr_trees++])
 -              return -1;
 -      trees[nr_trees] = parse_tree_indirect(remote);
 -      if (!trees[nr_trees++])
 -              return -1;
 -      for (i = 0; i < nr_trees; i++) {
 -              parse_tree(trees[i]);
 -              init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
 -      }
 -      if (unpack_trees(nr_trees, t, &opts))
 -              return -1;
 -      if (write_cache(fd, active_cache, active_nr) ||
 -              commit_locked_index(lock_file))
 -              die(_("unable to write new index file"));
 -      return 0;
 -}
 -
  static void split_merge_strategies(const char *string, struct strategy **list,
                                   int *nr, int *alloc)
  {
@@@ -800,9 -903,8 +800,9 @@@ static void prepare_to_commit(struct co
        if (0 < option_edit)
                strbuf_add_lines(&msg, "# ", comment, strlen(comment));
        write_merge_msg(&msg);
 -      run_hook(get_index_file(), "prepare-commit-msg",
 -               git_path("MERGE_MSG"), "merge", NULL, NULL);
 +      if (run_hook(get_index_file(), "prepare-commit-msg",
 +                   git_path("MERGE_MSG"), "merge", NULL, NULL))
 +              abort_commit(remoteheads, NULL);
        if (0 < option_edit) {
                if (launch_editor(git_path("MERGE_MSG"), NULL, NULL))
                        abort_commit(remoteheads, NULL);
@@@ -1222,6 -1324,7 +1222,7 @@@ int cmd_merge(int argc, const char **ar
                        memset(&opts, 0, sizeof(opts));
                        opts.add_title = !have_message;
                        opts.shortlog_len = shortlog_len;
+                       opts.credit_people = (0 < option_edit);
  
                        fmt_merge_msg(&merge_names, &merge_msg, &opts);
                        if (merge_msg.len)
                }
  
                if (checkout_fast_forward(head_commit->object.sha1,
 -                                        commit->object.sha1)) {
 +                                        commit->object.sha1,
 +                                        overwrite_ignore)) {
                        ret = 1;
                        goto done;
                }