summaryrefslogtreecommitdiff
path: root/src/diff.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-05-18 18:15:17 -0400
committerEdward Thomson <ethomson@microsoft.com>2015-05-28 09:44:18 -0400
commit191e97a02b3360820177ed7642116796551ce1f6 (patch)
tree2fe934a99dc08468b22344d074d1915e2d69440a /src/diff.c
parentb22369efa243022ff42582b559ddb6c6e05af2b1 (diff)
downloadlibgit2-191e97a02b3360820177ed7642116796551ce1f6.tar.gz
diff conflicts: don't include incorrect ID
Since a diff entry only concerns a single entry, zero the information for the index side of a conflict. (The index entry would otherwise erroneously include the lowest-stage index entry - generally the ancestor of a conflict.) Test that during status, the index side of the conflict is empty.
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/diff.c b/src/diff.c
index c061a903b..abe0de0d4 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -149,9 +149,10 @@ static int diff_delta__from_two(
uint32_t old_mode,
const git_index_entry *new_entry,
uint32_t new_mode,
- git_oid *new_oid,
+ const git_oid *new_id,
const char *matched_pathspec)
{
+ const git_oid *old_id = &old_entry->id;
git_diff_delta *delta;
const char *canonical_path = old_entry->path;
@@ -159,38 +160,42 @@ static int diff_delta__from_two(
DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNMODIFIED))
return 0;
+ if (!new_id)
+ new_id = &new_entry->id;
+
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) {
uint32_t temp_mode = old_mode;
const git_index_entry *temp_entry = old_entry;
+ const git_oid *temp_id = old_id;
+
old_entry = new_entry;
new_entry = temp_entry;
old_mode = new_mode;
new_mode = temp_mode;
+ old_id = new_id;
+ new_id = temp_id;
}
delta = diff_delta__alloc(diff, status, canonical_path);
GITERR_CHECK_ALLOC(delta);
delta->nfiles = 2;
- git_oid_cpy(&delta->old_file.id, &old_entry->id);
- delta->old_file.size = old_entry->file_size;
- delta->old_file.mode = old_mode;
- delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
+ if (!git_index_entry_stage(old_entry)) {
+ delta->old_file.size = old_entry->file_size;
+ delta->old_file.mode = old_mode;
+ git_oid_cpy(&delta->old_file.id, old_id);
+ delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
+ }
- git_oid_cpy(&delta->new_file.id, &new_entry->id);
- delta->new_file.size = new_entry->file_size;
- delta->new_file.mode = new_mode;
+ if (!git_index_entry_stage(new_entry)) {
+ git_oid_cpy(&delta->new_file.id, new_id);
+ delta->new_file.size = new_entry->file_size;
+ delta->new_file.mode = new_mode;
- if (new_oid) {
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE))
- git_oid_cpy(&delta->old_file.id, new_oid);
- else
- git_oid_cpy(&delta->new_file.id, new_oid);
+ if (!git_oid_iszero(&new_entry->id))
+ delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
}
- if (new_oid || !git_oid_iszero(&new_entry->id))
- delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
-
return diff_insert_delta(diff, delta, matched_pathspec);
}