@matheusbsbs / matheus-bagliano / commits / ab6854515e
Fork 0

status: don't require the repository to be writable

We need to update the index before hooks run when actually making a commit, but we shouldn't have to write the index when running "status". If we can, then we have already spent cycles to refresh the index and it is a waste not to write it out, but it is not a disaster if we cannot write it out. The main reason the user is running "git status" is to get the "status", and refreshing the index is a mere side effect that we can do without. Discovery and initial attempted fix by Dscho. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 19, 2010 at 17:10 UTC ab6854515ee2280f187fbc2ab08f9e9115438f3e
1 file changed +6 -4
builtin-commit.c
+6 -4
@@ -278,11 +278,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
278 * We still need to refresh the index here.
279 */
280 if (!pathspec || !*pathspec) {
281 - fd = hold_locked_index(&index_lock, 1);
281 + fd = hold_locked_index(&index_lock, !is_status);
282 refresh_cache(refresh_flags);
283 - if (write_cache(fd, active_cache, active_nr) ||
284 - commit_locked_index(&index_lock))
285 - die("unable to write new_index file");
283 + if (0 <= fd) {
284 + if (write_cache(fd, active_cache, active_nr) ||
285 + commit_locked_index(&index_lock))
286 + die("unable to write new_index file");
287 + }
288 commit_style = COMMIT_AS_IS;
289 return get_index_file();
290 }