Merge branch 'tc/merge-m-log'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jun 2010 18:16:54 +0000 (11:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jun 2010 18:16:54 +0000 (11:16 -0700)
* tc/merge-m-log:
merge: --log appends shortlog to message if specified
fmt-merge-msg: add function to append shortlog only
fmt-merge-msg: refactor merge title formatting
fmt-merge-msg: minor refactor of fmt_merge_msg()
merge: rename variable
merge: update comment
t7604-merge-custom-message: show that --log doesn't append to -m
t7604-merge-custom-message: shift expected output creation

Conflicts:
builtin.h

1  2 
builtin.h
builtin/merge.c
diff --combined builtin.h
index 5c887ef61bbf67411a81691c67fc14cc4e0bc682,322901f339a47486854d90048cbec198db8fce56..b614d12b9f3464eff9ecfa90c2eb5ecf43a82b7e
+++ b/builtin.h
@@@ -16,6 -16,10 +16,7 @@@ extern const char *help_unknown_cmd(con
  extern void prune_packed_objects(int);
  extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
        struct strbuf *out);
 -extern int commit_tree(const char *msg, unsigned char *tree,
 -              struct commit_list *parents, unsigned char *ret,
 -              const char *author);
+ extern int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out);
  extern int commit_notes(struct notes_tree *t, const char *msg);
  
  struct notes_rewrite_cfg {
diff --combined builtin/merge.c
index 37d414b3ba95162953aec001e6036956eb1a97f6,cae1cbee26535635cfe0d7e3a6f98e3a36e94cf7..37ce4f589f6582abf0d1ef5bd263f590a16853d5
@@@ -548,53 -548,13 +548,53 @@@ static void write_tree_trivial(unsigne
                die("git write-tree failed to write a tree");
  }
  
 -static int try_merge_strategy(const char *strategy, struct commit_list *common,
 -                            const char *head_arg)
 +int try_merge_command(const char *strategy, 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(sha1_to_hex(j->item->object.sha1));
 +      args[i++] = "--";
 +      args[i++] = head_arg;
 +      for (j = remotes; j; j = j->next)
 +              args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
 +      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,
 +                            const char *head_arg)
 +{
        int index_fd;
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
  
        rollback_lock_file(lock);
  
        if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
 -              int clean;
 +              int clean, x;
                struct commit *result;
                struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
                int index_fd;
                struct commit_list *reversed = NULL;
                struct merge_options o;
 +              struct commit_list *j;
  
                if (remoteheads->next) {
                        error("Not handling anything other than two heads merge.");
                rollback_lock_file(lock);
                return clean ? 0 : 1;
        } else {
 -              args = xmalloc((4 + xopts_nr + commit_list_count(common) +
 -                                      commit_list_count(remoteheads)) * 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(sha1_to_hex(j->item->object.sha1));
 -              args[i++] = "--";
 -              args[i++] = head_arg;
 -              for (j = remoteheads; j; j = j->next)
 -                      args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
 -              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 = remoteheads; 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;
 +              return try_merge_command(strategy, common, head_arg, remoteheads);
        }
  }
  
@@@ -982,7 -973,7 +982,7 @@@ int cmd_merge(int argc, const char **ar
                reset_hard(remote_head->sha1, 0);
                return 0;
        } else {
-               struct strbuf msg = STRBUF_INIT;
+               struct strbuf merge_names = STRBUF_INIT;
  
                /* We are invoked directly as the first-class UI. */
                head_arg = "HEAD";
                 * codepath so we discard the error in this
                 * loop.
                 */
-               if (!have_message) {
-                       for (i = 0; i < argc; i++)
-                               merge_name(argv[i], &msg);
-                       fmt_merge_msg(option_log, &msg, &merge_msg);
-                       if (merge_msg.len)
-                               strbuf_setlen(&merge_msg, merge_msg.len-1);
-               }
+               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 (head_invalid || !argc)