Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2e1b05

Browse files
swisspolethomson
authored andcommitted
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.
1 parent 619423f commit c2e1b05

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/diff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,10 @@ int git_diff__oid_for_entry(
664664
updated_entry.mode = mode;
665665
git_oid_cpy(&updated_entry.id, out);
666666

667-
if (!(error = git_repository_index__weakptr(&idx, diff->repo)))
667+
if (!(error = git_repository_index__weakptr(&idx, diff->repo))) {
668668
error = git_index_add(idx, &updated_entry);
669+
diff->index_updated = true;
670+
}
669671
}
670672

671673
git_buf_free(&full_path);
@@ -1360,7 +1362,7 @@ int git_diff_index_to_workdir(
13601362
&b, repo, index, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
13611363
);
13621364

1363-
if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX))
1365+
if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX) && (*diff)->index_updated)
13641366
error = git_index_write(index);
13651367

13661368
return error;

src/diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct git_diff {
6464
git_iterator_type_t new_src;
6565
uint32_t diffcaps;
6666
git_diff_perfdata perf;
67+
bool index_updated;
6768

6869
int (*strcomp)(const char *, const char *);
6970
int (*strncomp)(const char *, const char *, size_t);

0 commit comments

Comments
 (0)