Skip to content

Commit bff6e86

Browse files
committed
Merge branch 'jk/maint-status-keep-index-timestamp'
* jk/maint-status-keep-index-timestamp: do not write out index when status does not have to
2 parents 754e66b + d5f5d0a commit bff6e86

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

builtin/commit.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
343343
if (!pathspec || !*pathspec) {
344344
fd = hold_locked_index(&index_lock, 1);
345345
refresh_cache_or_die(refresh_flags);
346-
if (write_cache(fd, active_cache, active_nr) ||
347-
commit_locked_index(&index_lock))
348-
die("unable to write new_index file");
346+
if (active_cache_changed) {
347+
if (write_cache(fd, active_cache, active_nr) ||
348+
commit_locked_index(&index_lock))
349+
die("unable to write new_index file");
350+
} else {
351+
rollback_lock_file(&index_lock);
352+
}
349353
commit_style = COMMIT_AS_IS;
350354
return get_index_file();
351355
}
@@ -1085,9 +1089,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10851089

10861090
fd = hold_locked_index(&index_lock, 0);
10871091
if (0 <= fd) {
1088-
if (!write_cache(fd, active_cache, active_nr))
1092+
if (active_cache_changed &&
1093+
!write_cache(fd, active_cache, active_nr))
10891094
commit_locked_index(&index_lock);
1090-
rollback_lock_file(&index_lock);
1095+
else
1096+
rollback_lock_file(&index_lock);
10911097
}
10921098

10931099
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;

0 commit comments

Comments
 (0)