Code

Merge branch 'jc/checkout'
[git.git] / builtin-update-index.c
index 325cd0944dd81e1531dd097da3069c46a5321523..24dca47d8d6e54429aa89b04e4d67bda04fa0173 100644 (file)
@@ -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;
@@ -490,7 +489,7 @@ int cmd_update_index(int argc, const char **argv, char **envp)
        git_config(git_default_config);
 
        /* We can't free this memory, it becomes part of a linked list parsed atexit() */
-       lock_file = xmalloc(sizeof(struct lock_file));
+       lock_file = xcalloc(1, sizeof(struct lock_file));
 
        newfd = hold_lock_file_for_update(lock_file, get_index_file());
        if (newfd < 0)
@@ -648,7 +647,7 @@ int cmd_update_index(int argc, const char **argv, char **envp)
  finish:
        if (active_cache_changed) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_lock_file(lock_file))
+                   close(newfd) || commit_lock_file(lock_file))
                        die("Unable to write new index file");
        }