diff_tform: remove reversed copy of delta merger Drop `git_diff__merge_like_cgit_reversed`, since it's a copy and paste mess of slightly incompatible changes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 041592f..cc809c1 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -80,10 +80,11 @@ static git_diff_delta *diff_delta__merge_like_cgit(
return NULL;
/* If 'a' status is uninteresting, then we're done */
- if (a->status == GIT_DELTA_UNMODIFIED)
+ if (a->status == GIT_DELTA_UNMODIFIED ||
+ a->status == GIT_DELTA_UNTRACKED ||
+ a->status == GIT_DELTA_UNREADABLE)
return dup;
- assert(a->status != GIT_DELTA_UNMODIFIED);
assert(b->status != GIT_DELTA_UNMODIFIED);
/* A cgit exception is that the diff of a file that is only in the
@@ -108,47 +109,6 @@ static git_diff_delta *diff_delta__merge_like_cgit(
return dup;
}
-static git_diff_delta *diff_delta__merge_like_cgit_reversed(
- const git_diff_delta *a,
- const git_diff_delta *b,
- git_pool *pool)
-{
- git_diff_delta *dup;
-
- /* reversed version of above logic */
-
- if (a->status == GIT_DELTA_CONFLICTED)
- return diff_delta__dup(a, pool);
- if (b->status == GIT_DELTA_CONFLICTED)
- return diff_delta__dup(b, pool);
-
- if (a->status == GIT_DELTA_UNMODIFIED)
- return diff_delta__dup(b, pool);
-
- if ((dup = diff_delta__dup(a, pool)) == NULL)
- return NULL;
-
- if (b->status == GIT_DELTA_UNMODIFIED || b->status == GIT_DELTA_UNTRACKED || b->status == GIT_DELTA_UNREADABLE)
- return dup;
-
- if (dup->status == GIT_DELTA_DELETED) {
- if (b->status == GIT_DELTA_ADDED) {
- dup->status = GIT_DELTA_UNMODIFIED;
- dup->nfiles = 2;
- }
- } else {
- dup->status = b->status;
- dup->nfiles = b->nfiles;
- }
-
- git_oid_cpy(&dup->old_file.id, &b->old_file.id);
- dup->old_file.mode = b->old_file.mode;
- dup->old_file.size = b->old_file.size;
- dup->old_file.flags = b->old_file.flags;
-
- return dup;
-}
-
int git_diff_merge(git_diff *onto, const git_diff *from)
{
int error = 0;
@@ -191,9 +151,10 @@ int git_diff_merge(git_diff *onto, const git_diff *from)
delta = diff_delta__dup(f, &onto_pool);
j++;
} else {
- delta = reversed ?
- diff_delta__merge_like_cgit_reversed(o, f, &onto_pool) :
- diff_delta__merge_like_cgit(o, f, &onto_pool);
+ const git_diff_delta *left = reversed ? f : o;
+ const git_diff_delta *right = reversed ? o : f;
+
+ delta = diff_delta__merge_like_cgit(left, right, &onto_pool);
i++;
j++;
}