From 35df76bdd9536f1b02a04908871904da11292292 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Latour Date: Wed, 15 Apr 2015 15:27:56 -0700 Subject: [PATCH 1/3] Use git_oid_cpy() instead of memcpy() --- src/diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diff.c b/src/diff.c index f1bc28fd9..20f8f74c5 100644 --- a/src/diff.c +++ b/src/diff.c @@ -621,7 +621,7 @@ int git_diff__oid_for_entry( git_index *idx; if (!(error = git_repository_index__weakptr(&idx, diff->repo))) { - memcpy(&entry.id, out, sizeof(entry.id)); + git_oid_cpy(&entry.id, out); error = git_index_add(idx, &entry); } } From cc93ad16502ea09b1923ca9eb1b291ced646cf38 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Latour Date: Wed, 15 Apr 2015 15:27:59 -0700 Subject: [PATCH 2/3] Removed unnecessary condition The variable noid is guaranteed to be zero at this point of the code path. --- src/diff.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/diff.c b/src/diff.c index 20f8f74c5..ba8a1b884 100644 --- a/src/diff.c +++ b/src/diff.c @@ -806,15 +806,12 @@ static int maybe_modified( * haven't calculated the OID of the new item, then calculate it now */ if (modified_uncertain && git_oid_iszero(&nitem->id)) { - if (git_oid_iszero(&noid)) { - const git_oid *update_check = - DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) ? - &oitem->id : NULL; - - if ((error = git_diff__oid_for_entry( - &noid, diff, nitem, update_check)) < 0) - return error; - } + const git_oid *update_check = + DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) ? + &oitem->id : NULL; + if ((error = git_diff__oid_for_entry( + &noid, diff, nitem, update_check)) < 0) + return error; /* if oid matches, then mark unmodified (except submodules, where * the filesystem content may be modified even if the oid still From db853748f6ed90766f5878afdb1473fa11d950e3 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Latour Date: Wed, 15 Apr 2015 15:28:03 -0700 Subject: [PATCH 3/3] Fixed GIT_DIFF_UPDATE_INDEX not being aware of executable bit changes In the prior implementation, enabling GIT_DIFF_UPDATE_INDEX would overwrite entries in the index with the ones generated from scanning the working if the OID was the same. Because this OID comparison ignores file modes, this means an file in the workdir with only an exec bit difference with the one in the index would end up being overwritten, resulting in the exec bit being loss. There might be other related bugs but the fix of comparing OIDs and file modes should address them all. --- src/diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diff.c b/src/diff.c index ba8a1b884..08e218cce 100644 --- a/src/diff.c +++ b/src/diff.c @@ -807,7 +807,7 @@ static int maybe_modified( */ if (modified_uncertain && git_oid_iszero(&nitem->id)) { const git_oid *update_check = - DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) ? + DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) && omode == nmode ? &oitem->id : NULL; if ((error = git_diff__oid_for_entry( &noid, diff, nitem, update_check)) < 0)