summaryrefslogtreecommitdiff
path: root/src/diff.c
diff options
context:
space:
mode:
authorPierre-Olivier Latour <pol@mac.com>2015-06-05 18:26:49 -0700
committerEdward Thomson <ethomson@edwardthomson.com>2015-06-26 02:00:21 -0400
commitc2e1b0581ada8453447bdeaacca92d972d83b1a8 (patch)
treea0fa85c94a4adad6623f67562a92d95d80295466 /src/diff.c
parent619423f238b2c782173d1cf83864cbd1219ab6a7 (diff)
downloadlibgit2-c2e1b0581ada8453447bdeaacca92d972d83b1a8.tar.gz
Only write index if updated when passing GIT_DIFF_UPDATE_INDEX
When diffing the index with the workdir and GIT_DIFF_UPDATE_INDEX has been passed, the previous implementation was always writing the index to disk even if it wasn't modified.
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/diff.c b/src/diff.c
index 12d34a184..c1adcc662 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -664,8 +664,10 @@ int git_diff__oid_for_entry(
updated_entry.mode = mode;
git_oid_cpy(&updated_entry.id, out);
- if (!(error = git_repository_index__weakptr(&idx, diff->repo)))
+ if (!(error = git_repository_index__weakptr(&idx, diff->repo))) {
error = git_index_add(idx, &updated_entry);
+ diff->index_updated = true;
+ }
}
git_buf_free(&full_path);
@@ -1360,7 +1362,7 @@ int git_diff_index_to_workdir(
&b, repo, index, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
);
- if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX))
+ if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX) && (*diff)->index_updated)
error = git_index_write(index);
return error;