summaryrefslogtreecommitdiff
path: root/builtin/commit.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-07-06 21:53:11 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-07-06 21:53:11 -0700
commitd5f5d0a9443c3892cdf9665ed8e0f9004706ed65 (patch)
treed8ee6f246324d911ad44ad98a6d4cf6e6d47a88e /builtin/commit.c
parentxdiff: optimise for no whitespace difference when ignoring whitespace. (diff)
downloadtgif-d5f5d0a9443c3892cdf9665ed8e0f9004706ed65.tar.xz
do not write out index when status does not have to
Some codepaths, such as "git status" and "git commit --dry-run", tried to opportunisticly refresh the index and write the result out. But they did so without checking if there was actually any change that needs to be written out. Noticed by Jeff King and Daniel at Rutgers.edu Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit.c')
-rw-r--r--builtin/commit.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index 80c621dc06..da18287ca9 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -334,9 +334,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
if (!pathspec || !*pathspec) {
fd = hold_locked_index(&index_lock, 1);
refresh_cache_or_die(refresh_flags);
- if (write_cache(fd, active_cache, active_nr) ||
- commit_locked_index(&index_lock))
- die("unable to write new_index file");
+ if (active_cache_changed) {
+ if (write_cache(fd, active_cache, active_nr) ||
+ commit_locked_index(&index_lock))
+ die("unable to write new_index file");
+ } else {
+ rollback_lock_file(&index_lock);
+ }
commit_style = COMMIT_AS_IS;
return get_index_file();
}
@@ -1067,9 +1071,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
fd = hold_locked_index(&index_lock, 0);
if (0 <= fd) {
- if (!write_cache(fd, active_cache, active_nr))
+ if (active_cache_changed &&
+ !write_cache(fd, active_cache, active_nr))
commit_locked_index(&index_lock);
- rollback_lock_file(&index_lock);
+ else
+ rollback_lock_file(&index_lock);
}
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;