Merge branch 'mm/push-social-engineering-attack-doc'
[gitweb.git] / builtin / checkout.c
index 13169221b16a54fb0de5da5c2a73d179e4330045..bfe685c198cd38b59ffe66fa6b3d3a7bced60824 100644 (file)
@@ -154,8 +154,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
        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)) {
@@ -169,7 +169,7 @@ static int checkout_stage(int stage, struct cache_entry *ce, int pos,
                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;
@@ -239,7 +239,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                          const char *revision)
 {
        int pos;
-       struct checkout state;
+       struct checkout state = CHECKOUT_INIT;
        static char *ps_matched;
        struct object_id rev;
        struct commit *head;
@@ -274,7 +274,7 @@ static int checkout_paths(const struct checkout_opts *opts,
 
        lock_file = xcalloc(1, sizeof(struct lock_file));
 
-       hold_locked_index(lock_file, 1);
+       hold_locked_index(lock_file, LOCK_DIE_ON_ERROR);
        if (read_cache_preload(&opts->pathspec) < 0)
                return error(_("index file corrupt"));
 
@@ -352,7 +352,6 @@ static int checkout_paths(const struct checkout_opts *opts,
                return 1;
 
        /* Now we are committed to check them out */
-       memset(&state, 0, sizeof(state));
        state.force = 1;
        state.refresh_cache = 1;
        state.istate = &the_index;
@@ -468,7 +467,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
        int ret;
        struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
 
-       hold_locked_index(lock_file, 1);
+       hold_locked_index(lock_file, LOCK_DIE_ON_ERROR);
        if (read_cache_preload(NULL) < 0)
                return error(_("index file corrupt"));
 
@@ -548,7 +547,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
                         * entries in the index.
                         */
 
-                       add_files_to_cache(NULL, NULL, 0, 0);
+                       add_files_to_cache(NULL, NULL, 0);
                        /*
                         * NEEDSWORK: carrying over local changes
                         * when branches have different end-of-line
@@ -631,7 +630,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
                        }
                }
                else
-                       create_branch(old->name, opts->new_branch, new->name,
+                       create_branch(opts->new_branch, new->name,
                                      opts->new_branch_force ? 1 : 0,
                                      opts->new_branch_log,
                                      opts->new_branch_force ? 1 : 0,
@@ -973,7 +972,7 @@ static int parse_branchname_arg(int argc, const char **argv,
        if (!strcmp(arg, "-"))
                arg = "@{-1}";
 
-       if (get_sha1_mb(arg, rev->hash)) {
+       if (get_oid_mb(arg, rev)) {
                /*
                 * Either case (3) or (4), with <something> not being
                 * a commit, or an attempt to use case (1) with an
@@ -985,7 +984,7 @@ static int parse_branchname_arg(int argc, const char **argv,
                int recover_with_dwim = dwim_new_local_branch_ok;
 
                if (!has_dash_dash &&
-                   (check_filename(NULL, arg) || !no_wildcard(arg)))
+                   (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
                        recover_with_dwim = 0;
                /*
                 * Accept "git checkout foo" and "git checkout foo --"
@@ -1038,7 +1037,7 @@ static int parse_branchname_arg(int argc, const char **argv,
 
        if (!*source_tree)                   /* case (1): want a tree */
                die(_("reference is not a tree: %s"), arg);
-       if (!has_dash_dash) {/* case (3).(d) -> (1) */
+       if (!has_dash_dash) {   /* case (3).(d) -> (1) */
                /*
                 * Do not complain the most common case
                 *      git checkout branch
@@ -1046,7 +1045,7 @@ static int parse_branchname_arg(int argc, const char **argv,
                 * it would be extremely annoying.
                 */
                if (argc)
-                       verify_non_filename(NULL, arg);
+                       verify_non_filename(opts->prefix, arg);
        } else {
                argcount++;
                argv++;