entry.c: update cache_changed if refresh_cache is set in checkout_entry()
[gitweb.git] / builtin / update-index.c
index 00313f373aadd989e0627b0b3068676c66c17a9b..fa3c44140dd3020ea84f5527ba2f584d58f5ae3d 100644 (file)
@@ -12,6 +12,7 @@
 #include "resolve-undo.h"
 #include "parse-options.h"
 #include "pathspec.h"
+#include "dir.h"
 
 /*
  * Default to not allowing changes to the list of files. The
@@ -54,8 +55,8 @@ static int mark_ce_flags(const char *path, int flag, int mark)
                        active_cache[pos]->ce_flags |= flag;
                else
                        active_cache[pos]->ce_flags &= ~flag;
-               cache_tree_invalidate_path(active_cache_tree, path);
-               active_cache_changed = 1;
+               cache_tree_invalidate_path(&the_index, path);
+               active_cache_changed |= CE_ENTRY_CHANGED;
                return 0;
        }
        return -1;
@@ -266,8 +267,8 @@ static void chmod_path(int flip, const char *path)
        default:
                goto fail;
        }
-       cache_tree_invalidate_path(active_cache_tree, path);
-       active_cache_changed = 1;
+       cache_tree_invalidate_path(&the_index, path);
+       active_cache_changed |= CE_ENTRY_CHANGED;
        report("chmod %cx '%s'", flip, path);
        return;
  fail:
@@ -561,7 +562,7 @@ static int do_reupdate(int ac, const char **av,
                int save_nr;
                char *path;
 
-               if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
+               if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
                        continue;
                if (has_head)
                        old = read_one_ent(NULL, head_sha1,
@@ -628,14 +629,42 @@ static int resolve_undo_clear_callback(const struct option *opt,
        return 0;
 }
 
+static int parse_new_style_cacheinfo(const char *arg,
+                                    unsigned int *mode,
+                                    unsigned char sha1[],
+                                    const char **path)
+{
+       unsigned long ul;
+       char *endp;
+
+       errno = 0;
+       ul = strtoul(arg, &endp, 8);
+       if (errno || endp == arg || *endp != ',' || (unsigned int) ul != ul)
+               return -1; /* not a new-style cacheinfo */
+       *mode = ul;
+       endp++;
+       if (get_sha1_hex(endp, sha1) || endp[40] != ',')
+               return -1;
+       *path = endp + 41;
+       return 0;
+}
+
 static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,
                                const struct option *opt, int unset)
 {
        unsigned char sha1[20];
        unsigned int mode;
+       const char *path;
 
+       if (!parse_new_style_cacheinfo(ctx->argv[1], &mode, sha1, &path)) {
+               if (add_cacheinfo(mode, sha1, path, 0))
+                       die("git update-index: --cacheinfo cannot add %s", path);
+               ctx->argv++;
+               ctx->argc--;
+               return 0;
+       }
        if (ctx->argc <= 3)
-               return error("option 'cacheinfo' expects three arguments");
+               return error("option 'cacheinfo' expects <mode>,<sha1>,<path>");
        if (strtoul_ui(*++ctx->argv, 8, &mode) ||
            get_sha1_hex(*++ctx->argv, sha1) ||
            add_cacheinfo(mode, sha1, *++ctx->argv, 0))
@@ -739,9 +768,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        PARSE_OPT_NOARG | PARSE_OPT_NONEG,
                        really_refresh_callback},
                {OPTION_LOWLEVEL_CALLBACK, 0, "cacheinfo", NULL,
-                       N_("<mode> <object> <path>"),
+                       N_("<mode>,<object>,<path>"),
                        N_("add the specified entry to the index"),
-                       PARSE_OPT_NOARG |       /* disallow --cacheinfo=<mode> form */
+                       PARSE_OPT_NOARG | /* disallow --cacheinfo=<mode> form */
                        PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
                        (parse_opt_cb *) cacheinfo_callback},
                {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, N_("(+/-)x"),
@@ -860,7 +889,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                            INDEX_FORMAT_LB, INDEX_FORMAT_UB);
 
                if (the_index.version != preferred_index_format)
-                       active_cache_changed = 1;
+                       active_cache_changed |= SOMETHING_CHANGED;
                the_index.version = preferred_index_format;
        }
 
@@ -892,8 +921,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                                exit(128);
                        unable_to_lock_index_die(get_index_file(), lock_error);
                }
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(lock_file))
+               if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                        die("Unable to write new index file");
        }