Merge branch 'nd/switch-and-restore'
authorJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:27 +0000 (13:19 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:27 +0000 (13:19 +0900)
Resurrect a performance hack.

* nd/switch-and-restore:
checkout: add simple check for 'git checkout -b'

1  2 
builtin/checkout.c
diff --combined builtin/checkout.c
index 0a3679eb776ec962d943f3d1902c9c6e7f1feea7,2bca5fe4925638cfd2dd77a3b8f1836d326b902f..12837277615d3985fb995862c22ededfed728b8a
@@@ -126,7 -126,6 +126,7 @@@ static int update_some(const struct obj
        if (pos >= 0) {
                struct cache_entry *old = active_cache[pos];
                if (ce->ce_mode == old->ce_mode &&
 +                  !ce_intent_to_add(old) &&
                    oideq(&ce->oid, &old->oid)) {
                        old->ce_flags |= CE_UPDATE;
                        discard_cache_entry(ce);
@@@ -486,7 -485,7 +486,7 @@@ static int checkout_paths(const struct 
                                                        ps_matched,
                                                        opts);
  
 -      if (report_path_error(ps_matched, &opts->pathspec, opts->prefix)) {
 +      if (report_path_error(ps_matched, &opts->pathspec)) {
                free(ps_matched);
                return 1;
        }
@@@ -685,7 -684,7 +685,7 @@@ static int merge_working_tree(const str
                topts.initial_checkout = is_cache_unborn();
                topts.update = 1;
                topts.merge = 1;
 -              topts.gently = opts->merge && old_branch_info->commit;
 +              topts.quiet = opts->merge && old_branch_info->commit;
                topts.verbose_update = opts->show_progress;
                topts.fn = twoway_merge;
                if (opts->overwrite_ignore) {
                         */
                        struct tree *result;
                        struct tree *work;
 +                      struct tree *old_tree;
                        struct merge_options o;
 +                      struct strbuf sb = STRBUF_INIT;
 +
                        if (!opts->merge)
                                return 1;
  
                         */
                        if (!old_branch_info->commit)
                                return 1;
 +                      old_tree = get_commit_tree(old_branch_info->commit);
 +
 +                      if (repo_index_has_changes(the_repository, old_tree, &sb))
 +                              die(_("cannot continue with staged changes in "
 +                                    "the following files:\n%s"), sb.buf);
 +                      strbuf_release(&sb);
  
                        /* Do more real merge */
  
                        ret = merge_trees(&o,
                                          new_tree,
                                          work,
 -                                        get_commit_tree(old_branch_info->commit),
 +                                        old_tree,
                                          &result);
                        if (ret < 0)
                                exit(128);
@@@ -1708,6 -1698,15 +1708,15 @@@ int cmd_checkout(int argc, const char *
        opts.checkout_index = -2;    /* default on */
        opts.checkout_worktree = -2; /* default on */
  
+       if (argc == 3 && !strcmp(argv[1], "-b")) {
+               /*
+                * User ran 'git checkout -b <branch>' and expects
+                * the same behavior as 'git switch -c <branch>'.
+                */
+               opts.switch_branch_doing_nothing_is_ok = 0;
+               opts.only_merge_on_switching_branches = 1;
+       }
        options = parse_options_dup(checkout_options);
        options = add_common_options(&opts, options);
        options = add_common_switch_branch_options(&opts, options);
@@@ -1763,7 -1762,7 +1772,7 @@@ int cmd_restore(int argc, const char **
        struct option *options;
        struct option restore_options[] = {
                OPT_STRING('s', "source", &opts.from_treeish, "<tree-ish>",
 -                         N_("where the checkout from")),
 +                         N_("which tree-ish to checkout from")),
                OPT_BOOL('S', "staged", &opts.checkout_index,
                           N_("restore the index")),
                OPT_BOOL('W', "worktree", &opts.checkout_worktree,