Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Tue, 10 Nov 2009 20:36:26 +0000 (12:36 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Nov 2009 20:36:26 +0000 (12:36 -0800)
* maint:
merge: do not setup worktree twice
check-ref-format: update usage string

Conflicts:
builtin-check-ref-format.c

1  2 
builtin-check-ref-format.c
builtin-merge.c
index e3e7bdf52f0b1f597e6cfd3affcf75f41f183d75,96382e34477263275c8d1f3628e3db4755042a06..513f13463844388699334da00d13c5f8dd90b286
@@@ -7,28 -7,10 +7,32 @@@
  #include "builtin.h"
  #include "strbuf.h"
  
+ static const char builtin_check_ref_format_usage[] =
+ "git check-ref-format [--print] <refname>\n"
+ "   or: git check-ref-format --branch <branchname-shorthand>";
 +/*
 + * Replace each run of adjacent slashes in src with a single slash,
 + * and write the result to dst.
 + *
 + * This function is similar to normalize_path_copy(), but stripped down
 + * to meet check_ref_format's simpler needs.
 + */
 +static void collapse_slashes(char *dst, const char *src)
 +{
 +      char ch;
 +      char prev = '\0';
 +
 +      while ((ch = *src++) != '\0') {
 +              if (prev == '/' && ch == prev)
 +                      continue;
 +
 +              *dst++ = ch;
 +              prev = ch;
 +      }
 +      *dst = '\0';
 +}
 +
  int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
  {
        if (argc == 3 && !strcmp(argv[1], "--branch")) {
                printf("%s\n", sb.buf + 11);
                exit(0);
        }
 +      if (argc == 3 && !strcmp(argv[1], "--print")) {
 +              char *refname = xmalloc(strlen(argv[2]) + 1);
 +
 +              if (check_ref_format(argv[2]))
 +                      exit(1);
 +              collapse_slashes(refname, argv[2]);
 +              printf("%s\n", refname);
 +              exit(0);
 +      }
        if (argc != 2)
-               usage("git check-ref-format refname");
+               usage(builtin_check_ref_format_usage);
        return !!check_ref_format(argv[1]);
  }
diff --combined builtin-merge.c
index 1ff7b15803fef8791c5c47209ba6f983d59f3065,e95c5dc71746fb6f4e87913669701a2f65070602..c8d7bdecc4e91392fa9e2614a6b9790e48fc0abd
@@@ -43,7 -43,6 +43,7 @@@ static const char * const builtin_merge
  
  static int show_diffstat = 1, option_log, squash;
  static int option_commit = 1, allow_fast_forward = 1;
 +static int fast_forward_only;
  static int allow_trivial = 1, have_message;
  static struct strbuf merge_msg;
  static struct commit_list *remoteheads;
@@@ -168,8 -167,6 +168,8 @@@ static struct option builtin_merge_opti
                "perform a commit if the merge succeeds (default)"),
        OPT_BOOLEAN(0, "ff", &allow_fast_forward,
                "allow fast forward (default)"),
 +      OPT_BOOLEAN(0, "ff-only", &fast_forward_only,
 +              "abort if fast forward is not possible"),
        OPT_CALLBACK('s', "strategy", &use_strategies, "strategy",
                "merge strategy to use", option_parse_strategy),
        OPT_CALLBACK('m', "message", &merge_msg, "message",
@@@ -267,7 -264,6 +267,7 @@@ static void squash_message(void
        struct strbuf out = STRBUF_INIT;
        struct commit_list *j;
        int fd;
 +      struct pretty_print_context ctx = {0};
  
        printf("Squash commit -- not updating HEAD\n");
        fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666);
        if (prepare_revision_walk(&rev))
                die("revision walk setup failed");
  
 +      ctx.abbrev = rev.abbrev;
 +      ctx.date_mode = rev.date_mode;
 +
        strbuf_addstr(&out, "Squashed commit of the following:\n");
        while ((commit = get_revision(&rev)) != NULL) {
                strbuf_addch(&out, '\n');
                strbuf_addf(&out, "commit %s\n",
                        sha1_to_hex(commit->object.sha1));
 -              pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
 -                      NULL, NULL, rev.date_mode, 0);
 +              pretty_print_commit(rev.commit_format, commit, &out, &ctx);
        }
        if (write(fd, out.buf, out.len) < 0)
                die_errno("Writing SQUASH_MSG");
@@@ -846,7 -840,6 +846,6 @@@ int cmd_merge(int argc, const char **ar
        const char *best_strategy = NULL, *wt_strategy = NULL;
        struct commit_list **remotes = &remoteheads;
  
-       setup_work_tree();
        if (file_exists(git_path("MERGE_HEAD")))
                die("You have not concluded your merge. (MERGE_HEAD exists)");
        if (read_cache_unmerged())
                option_commit = 0;
        }
  
 +      if (!allow_fast_forward && fast_forward_only)
 +              die("You cannot combine --no-ff with --ff-only.");
 +
        if (!argc)
                usage_with_options(builtin_merge_usage,
                        builtin_merge_options);
                 * only one common.
                 */
                refresh_cache(REFRESH_QUIET);
 -              if (allow_trivial) {
 +              if (allow_trivial && !fast_forward_only) {
                        /* See if it is really trivial. */
                        git_committer_info(IDENT_ERROR_ON_NO_NAME);
                        printf("Trying really trivial in-index merge...\n");
                }
        }
  
 +      if (fast_forward_only)
 +              die("Not possible to fast forward, aborting.");
 +
        /* We are going to make a new commit. */
        git_committer_info(IDENT_ERROR_ON_NO_NAME);