]> asedeno.scripts.mit.edu Git - git.git/commitdiff
Merge branch 'rr/fmt-merge-msg'
authorJunio C Hamano <gitster@pobox.com>
Wed, 29 Sep 2010 20:48:20 +0000 (13:48 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Sep 2010 20:48:20 +0000 (13:48 -0700)
* rr/fmt-merge-msg:
  t6200-fmt-merge-msg: Exercise '--log' to configure shortlog length
  t6200-fmt-merge-msg: Exercise 'merge.log' to configure shortlog length
  merge: Make 'merge.log' an integer or boolean option
  merge: Make '--log' an integer option for number of shortlog entries
  fmt_merge_msg: Change fmt_merge_msg API to accept shortlog_len

Conflicts:
builtin/merge.c

1  2 
Documentation/merge-config.txt
builtin.h
builtin/fmt-merge-msg.c
builtin/merge.c

index b72f5339704e89087992b7d6060e88f43b9d661b,acbe1e16b2c6b3ea5f7cfe20a9a3794c6e982ac8..92772e7c4eb8921d3b2763fe1b533c380bd2b92b
@@@ -7,24 -7,16 +7,26 @@@ merge.conflictstyle:
        marker and the original text before the `=======` marker.
  
  merge.log::
-       Whether to include summaries of merged commits in newly created
-       merge commit messages. False by default.
+       In addition to branch names, populate the log message with at
+       most the specified number of one-line descriptions from the
+       actual commits that are being merged.  Defaults to false, and
+       true is a synoym for 20.
  
  merge.renameLimit::
        The number of files to consider when performing rename detection
        during a merge; if not specified, defaults to the value of
        diff.renameLimit.
  
 +merge.renormalize::
 +      Tell git that canonical representation of files in the
 +      repository has changed over time (e.g. earlier commits record
 +      text files with CRLF line endings, but recent ones use LF line
 +      endings).  In such a repository, git can convert the data
 +      recorded in commits to a canonical form before performing a
 +      merge to reduce unnecessary conflicts.  For more information,
 +      see section "Merging branches with differing checkin/checkout
 +      attributes" in linkgit:gitattributes[5].
 +
  merge.stat::
        Whether to print the diffstat between ORIG_HEAD and the merge result
        at the end of the merge.  True by default.
diff --combined builtin.h
index 0398d247400e55f2a2ededc054902374c7516d5b,09b94ea4409ed497aff68012baad897de961e80d..f2a25a084736e573f560672fabc9c6214997f437
+++ b/builtin.h
@@@ -7,14 -7,17 +7,15 @@@
  #include "commit.h"
  #include "notes.h"
  
+ #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 list_common_cmds_help(void);
 -extern const char *help_unknown_cmd(const char *cmd);
  extern void prune_packed_objects(int);
- extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
-       struct strbuf *out);
- extern int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out);
+ extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
+                        int merge_title, int shortlog_len);
  extern int commit_notes(struct notes_tree *t, const char *msg);
  
  struct notes_rewrite_cfg {
diff --combined builtin/fmt-merge-msg.c
index e7e12eea250691a2c0d70964d1fffea0923dd292,d2eed43ab5c165f3b0ed10ba3df4296fc4679dd2..78c77742b6e6863b1eb4d61750ae253710223aa2
@@@ -7,21 -7,22 +7,22 @@@
  #include "string-list.h"
  
  static const char * const fmt_merge_msg_usage[] = {
-       "git fmt-merge-msg [-m <message>] [--log|--no-log] [--file <file>]",
+       "git fmt-merge-msg [-m <message>] [--log[=<n>]|--no-log] [--file <file>]",
        NULL
  };
  
- static int merge_summary;
+ static int shortlog_len;
  
  static int fmt_merge_msg_config(const char *key, const char *value, void *cb)
  {
-       static int found_merge_log = 0;
-       if (!strcmp("merge.log", key)) {
-               found_merge_log = 1;
-               merge_summary = git_config_bool(key, value);
+       if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
+               int is_bool;
+               shortlog_len = git_config_bool_or_int(key, value, &is_bool);
+               if (!is_bool && shortlog_len < 0)
+                       return error("%s: negative length %s", key, value);
+               if (is_bool && shortlog_len)
+                       shortlog_len = DEFAULT_MERGE_LOG_LEN;
        }
-       if (!found_merge_log && !strcmp("merge.summary", key))
-               merge_summary = git_config_bool(key, value);
        return 0;
  }
  
@@@ -38,8 -39,8 +39,8 @@@ void init_src_data(struct src_data *dat
        data->generic.strdup_strings = 1;
  }
  
 -static struct string_list srcs = { NULL, 0, 0, 1 };
 -static struct string_list origins = { NULL, 0, 0, 1 };
 +static struct string_list srcs = STRING_LIST_INIT_DUP;
 +static struct string_list origins = STRING_LIST_INIT_DUP;
  
  static int handle_line(char *line)
  {
@@@ -146,7 -147,7 +147,7 @@@ static void shortlog(const char *name, 
        int i, count = 0;
        struct commit *commit;
        struct object *branch;
 -      struct string_list subjects = { NULL, 0, 0, 1 };
 +      struct string_list subjects = STRING_LIST_INIT_DUP;
        int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
        struct strbuf sb = STRBUF_INIT;
  
@@@ -255,9 -256,9 +256,9 @@@ static void do_fmt_merge_msg_title(stru
                strbuf_addf(out, " into %s\n", current_branch);
  }
  
- static int do_fmt_merge_msg(int merge_title, int merge_summary,
-       struct strbuf *in, struct strbuf *out) {
-       int limit = 20, i = 0, pos = 0;
+ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
+       struct strbuf *out, int shortlog_len) {
+       int i = 0, pos = 0;
        unsigned char head_sha1[20];
        const char *current_branch;
  
        if (merge_title)
                do_fmt_merge_msg_title(out, current_branch);
  
-       if (merge_summary) {
+       if (shortlog_len) {
                struct commit *head;
                struct rev_info rev;
  
  
                for (i = 0; i < origins.nr; i++)
                        shortlog(origins.items[i].string, origins.items[i].util,
-                                       head, &rev, limit, out);
+                                       head, &rev, shortlog_len, out);
        }
        return 0;
  }
  
- int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {
-       return do_fmt_merge_msg(1, merge_summary, in, out);
- }
- int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) {
-       return do_fmt_merge_msg(0, 1, in, out);
+ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
+                 int merge_title, int shortlog_len) {
+       return do_fmt_merge_msg(merge_title, in, out, shortlog_len);
  }
  
  int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
        const char *inpath = NULL;
        const char *message = NULL;
        struct option options[] = {
-               OPT_BOOLEAN(0, "log",     &merge_summary, "populate log with the shortlog"),
-               { OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL,
+               { OPTION_INTEGER, 0, "log", &shortlog_len, "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)",
-                 PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
+                 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"),
                             0);
        if (argc > 0)
                usage_with_options(fmt_merge_msg_usage, options);
-       if (message && !merge_summary) {
+       if (message && !shortlog_len) {
                char nl = '\n';
                write_in_full(STDOUT_FILENO, message, strlen(message));
                write_in_full(STDOUT_FILENO, &nl, 1);
                return 0;
        }
+       if (shortlog_len < 0)
+               die("Negative --log=%d", shortlog_len);
  
        if (inpath && strcmp(inpath, "-")) {
                in = fopen(inpath, "r");
  
        if (strbuf_read(&input, fileno(in), 0) < 0)
                die_errno("could not read input file");
-       if (message) {
+       if (message)
                strbuf_addstr(&output, message);
-               ret = fmt_merge_msg_shortlog(&input, &output);
-       } else {
-               ret = fmt_merge_msg(merge_summary, &input, &output);
-       }
+       ret = fmt_merge_msg(&input, &output,
+                           message ? 0 : 1,
+                           shortlog_len);
        if (ret)
                return ret;
        write_in_full(STDOUT_FILENO, output.buf, output.len);
diff --combined builtin/merge.c
index 5f65c0c8a6eacd4c6d05602ad9de2821ec62a034,1e9c898aec2834577689b430739607a50508498a..2dba3b9901cbdca9aee279339ecd3537e15e39da
@@@ -42,7 -42,7 +42,7 @@@ static const char * const builtin_merge
        NULL
  };
  
- static int show_diffstat = 1, option_log, squash;
+ static int show_diffstat = 1, shortlog_len, squash;
  static int option_commit = 1, allow_fast_forward = 1;
  static int fast_forward_only;
  static int allow_trivial = 1, have_message;
@@@ -54,7 -54,6 +54,7 @@@ static size_t use_strategies_nr, use_st
  static const char **xopts;
  static size_t xopts_nr, xopts_alloc;
  static const char *branch;
 +static int option_renormalize;
  static int verbosity;
  static int allow_rerere_auto;
  
@@@ -132,7 -131,6 +132,7 @@@ static struct strategy *get_strategy(co
  
        ret = xcalloc(1, sizeof(struct strategy));
        ret->name = xstrdup(name);
 +      ret->attr = NO_TRIVIAL;
        return ret;
  }
  
@@@ -177,8 -175,9 +177,9 @@@ static struct option builtin_merge_opti
        OPT_BOOLEAN(0, "stat", &show_diffstat,
                "show a diffstat at the end of the merge"),
        OPT_BOOLEAN(0, "summary", &show_diffstat, "(synonym to --stat)"),
-       OPT_BOOLEAN(0, "log", &option_log,
-               "add list of one-line log to merge commit message"),
+       { OPTION_INTEGER, 0, "log", &shortlog_len, "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"),
        OPT_BOOLEAN(0, "commit", &option_commit,
@@@ -488,8 -487,7 +489,8 @@@ static int git_merge_config(const char 
                buf = xstrdup(v);
                argc = split_cmdline(buf, &argv);
                if (argc < 0)
 -                      die("Bad branch.%s.mergeoptions string", branch);
 +                      die("Bad branch.%s.mergeoptions string: %s", branch,
 +                          split_cmdline_strerror(argc));
                argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
                memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
                argc++;
                return git_config_string(&pull_twohead, k, v);
        else if (!strcmp(k, "pull.octopus"))
                return git_config_string(&pull_octopus, k, v);
-       else if (!strcmp(k, "merge.log") || !strcmp(k, "merge.summary"))
-               option_log = git_config_bool(k, v);
 +      else if (!strcmp(k, "merge.renormalize"))
 +              option_renormalize = git_config_bool(k, v);
+       else if (!strcmp(k, "merge.log") || !strcmp(k, "merge.summary")) {
+               int is_bool;
+               shortlog_len = git_config_bool_or_int(k, v, &is_bool);
+               if (!is_bool && shortlog_len < 0)
+                       return error("%s: negative length %s", k, v);
+               if (is_bool && shortlog_len)
+                       shortlog_len = DEFAULT_MERGE_LOG_LEN;
+               return 0;
+       }
        return git_diff_ui_config(k, v, cb);
  }
  
@@@ -629,11 -632,6 +637,11 @@@ static int try_merge_strategy(const cha
                if (!strcmp(strategy, "subtree"))
                        o.subtree_shift = "";
  
 +              o.renormalize = option_renormalize;
 +
 +              /*
 +               * NEEDSWORK: merge with table in builtin/merge-recursive
 +               */
                for (x = 0; x < xopts_nr; x++) {
                        if (!strcmp(xopts[x], "ours"))
                                o.recursive_variant = MERGE_RECURSIVE_OURS;
                                o.subtree_shift = "";
                        else if (!prefixcmp(xopts[x], "subtree="))
                                o.subtree_shift = xopts[x]+8;
 +                      else if (!strcmp(xopts[x], "renormalize"))
 +                              o.renormalize = 1;
 +                      else if (!strcmp(xopts[x], "no-renormalize"))
 +                              o.renormalize = 0;
                        else
                                die("Unknown option for merge-recursive: -X%s", xopts[x]);
                }
@@@ -718,7 -712,7 +726,7 @@@ int checkout_fast_forward(const unsigne
        opts.verbose_update = 1;
        opts.merge = 1;
        opts.fn = twoway_merge;
 -      opts.msgs = get_porcelain_error_msgs();
 +      setup_unpack_trees_porcelain(&opts, "merge");
  
        trees[nr_trees] = parse_tree_indirect(head);
        if (!trees[nr_trees++])
@@@ -830,7 -824,7 +838,7 @@@ static int finish_automerge(struct comm
        return 0;
  }
  
 -static int suggest_conflicts(void)
 +static int suggest_conflicts(int renormalizing)
  {
        FILE *fp;
        int pos;
@@@ -1012,14 -1006,12 +1020,12 @@@ int cmd_merge(int argc, const char **ar
                for (i = 0; i < argc; i++)
                        merge_name(argv[i], &merge_names);
  
-               if (have_message && option_log)
-                       fmt_merge_msg_shortlog(&merge_names, &merge_msg);
-               else if (!have_message)
-                       fmt_merge_msg(option_log, &merge_names, &merge_msg);
-               if (!(have_message && !option_log) && merge_msg.len)
-                       strbuf_setlen(&merge_msg, merge_msg.len-1);
+               if (!have_message || shortlog_len) {
+                       fmt_merge_msg(&merge_names, &merge_msg, !have_message,
+                                     shortlog_len);
+                       if (merge_msg.len)
+                               strbuf_setlen(&merge_msg, merge_msg.len - 1);
+               }
        }
  
        if (head_invalid || !argc)
                        "stopped before committing as requested\n");
                return 0;
        } else
 -              return suggest_conflicts();
 +              return suggest_conflicts(option_renormalize);
  }