diff options
Diffstat (limited to 'src/diff.c')
-rw-r--r-- | src/diff.c | 37 |
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); } |