Merge branch 'rs/checkout-some-states-are-const' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 29 Sep 2016 23:49:35 +0000 (16:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Sep 2016 23:49:35 +0000 (16:49 -0700)
Code cleanup.

* rs/checkout-some-states-are-const:
checkout: constify parameters of checkout_stage() and checkout_merged()

1  2 
builtin/checkout.c
diff --combined builtin/checkout.c
index 8672d0724ffec4bc0a74ba2c60d3a4dd0f504a21,161f1636a65805c255a9cb25e6a2be4e633c07ca..afbff3e7903775caabf76399fa0066af9369a7f2
@@@ -154,8 -154,8 +154,8 @@@ static int check_stages(unsigned stages
        return 0;
  }
  
- static int checkout_stage(int stage, struct cache_entry *ce, int pos,
-                         struct checkout *state)
+ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
+                         const struct checkout *state)
  {
        while (pos < active_nr &&
               !strcmp(active_cache[pos]->name, ce->name)) {
                return error(_("path '%s' does not have their version"), ce->name);
  }
  
- static int checkout_merged(int pos, struct checkout *state)
+ static int checkout_merged(int pos, const struct checkout *state)
  {
        struct cache_entry *ce = active_cache[pos];
        const char *path = ce->name;
@@@ -242,6 -242,7 +242,6 @@@ static int checkout_paths(const struct 
        struct checkout state;
        static char *ps_matched;
        unsigned char rev[20];
 -      int flag;
        struct commit *head;
        int errs = 0;
        struct lock_file *lock_file;
  
        hold_locked_index(lock_file, 1);
        if (read_cache_preload(&opts->pathspec) < 0)
 -              return error(_("corrupt index file"));
 +              return error(_("index file corrupt"));
  
        if (opts->source_tree)
                read_tree_some(opts->source_tree, &opts->pathspec);
        if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
  
 -      read_ref_full("HEAD", 0, rev, &flag);
 +      read_ref_full("HEAD", 0, rev, NULL);
        head = lookup_commit_reference_gently(rev, 1);
  
        errs |= post_checkout_hook(head, head, 0);
@@@ -470,7 -471,7 +470,7 @@@ static int merge_working_tree(const str
  
        hold_locked_index(lock_file, 1);
        if (read_cache_preload(NULL) < 0)
 -              return error(_("corrupt index file"));
 +              return error(_("index file corrupt"));
  
        resolve_undo_clear();
        if (opts->force) {
                         * entries in the index.
                         */
  
 -                      add_files_to_cache(NULL, NULL, 0);
 +                      add_files_to_cache(NULL, NULL, 0, 0);
                        /*
                         * NEEDSWORK: carrying over local changes
                         * when branches have different end-of-line
                        o.ancestor = old->name;
                        o.branch1 = new->name;
                        o.branch2 = "local";
 -                      merge_trees(&o, new->commit->tree, work,
 +                      ret = merge_trees(&o, new->commit->tree, work,
                                old->commit->tree, &result);
 +                      if (ret < 0)
 +                              exit(128);
                        ret = reset_tree(new->commit->tree, opts, 0,
                                         writeout_error);
 +                      strbuf_release(&o.obuf);
                        if (ret)
                                return ret;
                }
@@@ -658,8 -656,7 +658,8 @@@ static void update_refs_for_switch(cons
                update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
                           REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
                if (!opts->quiet) {
 -                      if (old->path && advice_detached_head)
 +                      if (old->path &&
 +                          advice_detached_head && !opts->force_detach)
                                detach_advice(new->name);
                        describe_detached_head(_("HEAD is now at"), new->commit);
                }
@@@ -707,7 -704,8 +707,7 @@@ static int add_pending_uninteresting_re
  static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
  {
        strbuf_addstr(sb, "  ");
 -      strbuf_addstr(sb,
 -              find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
 +      strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
        strbuf_addch(sb, ' ');
        if (!parse_commit(commit))
                pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
@@@ -1113,7 -1111,7 +1113,7 @@@ static int checkout_branch(struct check
                char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
                if (head_ref &&
                    (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
 -                      die_if_checked_out(new->path);
 +                      die_if_checked_out(new->path, 1);
                free(head_ref);
        }
  
@@@ -1141,7 -1139,7 +1141,7 @@@ int cmd_checkout(int argc, const char *
                OPT_STRING('B', NULL, &opts.new_branch_force, N_("branch"),
                           N_("create/reset and checkout a branch")),
                OPT_BOOL('l', NULL, &opts.new_branch_log, N_("create reflog for new branch")),
 -              OPT_BOOL(0, "detach", &opts.force_detach, N_("detach the HEAD at named commit")),
 +              OPT_BOOL(0, "detach", &opts.force_detach, N_("detach HEAD at named commit")),
                OPT_SET_INT('t', "track",  &opts.track, N_("set upstream info for new branch"),
                        BRANCH_TRACK_EXPLICIT),
                OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new-branch"), N_("new unparented branch")),