summaryrefslogtreecommitdiff
path: root/src/diff.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-09-25 10:48:50 -0700
committerRussell Belfer <rb@github.com>2012-09-25 16:35:05 -0700
commit642863086575a61b3ed0bbbe909f4f07d87ff9db (patch)
tree22cb6c0d2355e4a15edd645104b39fe2c33c97ac /src/diff.c
parent5f69a31f7d706aa5788ad9937391577a66e3c77d (diff)
downloadlibgit2-642863086575a61b3ed0bbbe909f4f07d87ff9db.tar.gz
Fix bugs in new diff patch code
This fixes all the bugs in the new diff patch code. The only really interesting one is that when we merge two diffs, we now have to actually exclude diff delta records that are not supposed to be tracked, as opposed to before where they could be included because they would be skipped silently by `git_diff_foreach()`. Other than that, there are just minor errors.
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/diff.c b/src/diff.c
index 7c8e2a9bb..7ee919b5a 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -807,6 +807,28 @@ on_error:
return -1;
}
+
+bool git_diff_delta__should_skip(
+ git_diff_options *opts, git_diff_delta *delta)
+{
+ uint32_t flags = opts ? opts->flags : 0;
+
+ if (delta->status == GIT_DELTA_UNMODIFIED &&
+ (flags & GIT_DIFF_INCLUDE_UNMODIFIED) == 0)
+ return true;
+
+ if (delta->status == GIT_DELTA_IGNORED &&
+ (flags & GIT_DIFF_INCLUDE_IGNORED) == 0)
+ return true;
+
+ if (delta->status == GIT_DELTA_UNTRACKED &&
+ (flags & GIT_DIFF_INCLUDE_UNTRACKED) == 0)
+ return true;
+
+ return false;
+}
+
+
int git_diff_merge(
git_diff_list *onto,
const git_diff_list *from)
@@ -843,6 +865,14 @@ int git_diff_merge(
j++;
}
+ /* the ignore rules for the target may not match the source
+ * or the result of a merged delta could be skippable...
+ */
+ if (git_diff_delta__should_skip(&onto->opts, delta)) {
+ git__free(delta);
+ continue;
+ }
+
if ((error = !delta ? -1 : git_vector_insert(&onto_new, delta)) < 0)
break;
}