Code

git_dir holds pointers to local strings, hence MUST be const.
[git.git] / builtin-update-index.c
index 1a4200d151dd8e876c6f84531422cae50b049aa3..5dd91af180df0f832ecc747050ad5306efe9c8b6 100644 (file)
@@ -23,7 +23,7 @@ static int allow_replace;
 static int info_only;
 static int force_remove;
 static int verbose;
-static int mark_valid_only = 0;
+static int mark_valid_only;
 #define MARK_VALID 1
 #define UNMARK_VALID 2
 
@@ -378,7 +378,7 @@ static int unresolve_one(const char *path)
                ret = -1;
                goto free_return;
        }
-       if (!memcmp(ce_2->sha1, ce_3->sha1, 20) &&
+       if (!hashcmp(ce_2->sha1, ce_3->sha1) &&
            ce_2->ce_mode == ce_3->ce_mode) {
                fprintf(stderr, "%s: identical in both, skipping.\n",
                        path);
@@ -460,7 +460,7 @@ static int do_reupdate(int ac, const char **av,
                        old = read_one_ent(NULL, head_sha1,
                                           ce->name, ce_namelen(ce), 0);
                if (old && ce->ce_mode == old->ce_mode &&
-                   !memcmp(ce->sha1, old->sha1, 20)) {
+                   !hashcmp(ce->sha1, old->sha1)) {
                        free(old);
                        continue; /* unchanged */
                }
@@ -476,12 +476,11 @@ static int do_reupdate(int ac, const char **av,
        return 0;
 }
 
-int cmd_update_index(int argc, const char **argv, char **envp)
+int cmd_update_index(int argc, const char **argv, const char *prefix)
 {
        int i, newfd, entries, has_errors = 0, line_termination = '\n';
        int allow_options = 1;
        int read_from_stdin = 0;
-       const char *prefix = setup_git_directory();
        int prefix_length = prefix ? strlen(prefix) : 0;
        char set_executable_bit = 0;
        unsigned int refresh_flags = 0;
@@ -492,9 +491,7 @@ int cmd_update_index(int argc, const char **argv, char **envp)
        /* We can't free this memory, it becomes part of a linked list parsed atexit() */
        lock_file = xcalloc(1, sizeof(struct lock_file));
 
-       newfd = hold_lock_file_for_update(lock_file, get_index_file());
-       if (newfd < 0)
-               die("unable to create new cachefile");
+       newfd = hold_lock_file_for_update(lock_file, get_index_file(), 1);
 
        entries = read_cache();
        if (entries < 0)