Merge branch 'cc/replace-with-the-same-type'
[gitweb.git] / builtin / reset.c
index 5e4c551531896ebd993d2a2c2903e4b7d257ed31..1a5344877212e675d685055a631aba2ac0a4c661 100644 (file)
@@ -226,7 +226,7 @@ static void parse_args(struct pathspec *pathspec,
                       prefix, argv);
 }
 
-static int update_refs(const char *rev, const unsigned char *sha1)
+static int reset_refs(const char *rev, const unsigned char *sha1)
 {
        int update_ref_status;
        struct strbuf msg = STRBUF_INIT;
@@ -330,11 +330,14 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                die_if_unmerged_cache(reset_type);
 
        if (reset_type != SOFT) {
-               struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
+               struct lock_file *lock = xcalloc(1, sizeof(*lock));
                int newfd = hold_locked_index(lock, 1);
                if (reset_type == MIXED) {
+                       int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
                        if (read_from_tree(&pathspec, sha1))
                                return 1;
+                       refresh_index(&the_index, flags, NULL, NULL,
+                                     _("Unstaged changes after reset:"));
                } else {
                        int err = reset_index(sha1, reset_type, quiet);
                        if (reset_type == KEEP && !err)
@@ -343,12 +346,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                                die(_("Could not reset index file to revision '%s'."), rev);
                }
 
-               if (reset_type == MIXED) { /* Report what has not been updated. */
-                       int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
-                       refresh_index(&the_index, flags, NULL, NULL,
-                                     _("Unstaged changes after reset:"));
-               }
-
                if (write_cache(newfd, active_cache, active_nr) ||
                    commit_locked_index(lock))
                        die(_("Could not write new index file."));
@@ -357,7 +354,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
        if (!pathspec.nr && !unborn) {
                /* Any resets without paths update HEAD to the head being
                 * switched to, saving the previous head in ORIG_HEAD before. */
-               update_ref_status = update_refs(rev, sha1);
+               update_ref_status = reset_refs(rev, sha1);
 
                if (reset_type == HARD && !update_ref_status && !quiet)
                        print_new_head_line(lookup_commit_reference(sha1));