Reorganize FORCE_TEXT diff flag checks
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
diff --git a/src/diff_output.c b/src/diff_output.c
index 2e0be63..26b073a 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -89,13 +89,14 @@ static void update_delta_is_binary(git_diff_delta *delta)
/* otherwise leave delta->binary value untouched */
}
-static int diff_delta_is_binary_by_attr(
- diff_context *ctxt, git_diff_patch *patch)
+/* returns if we forced binary setting (and no further checks needed) */
+static bool diff_delta_is_binary_forced(
+ diff_context *ctxt,
+ git_diff_delta *delta)
{
- int error = 0, mirror_new;
- git_diff_delta *delta = patch->delta;
-
- delta->binary = -1;
+ /* return true if binary-ness has already been settled */
+ if (delta->binary != -1)
+ return true;
/* make sure files are conceivably mmap-able */
if ((git_off_t)((size_t)delta->old_file.size) != delta->old_file.size ||
@@ -104,7 +105,7 @@ static int diff_delta_is_binary_by_attr(
delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
delta->binary = 1;
- return 0;
+ return true;
}
/* check if user is forcing us to text diff these files */
@@ -112,9 +113,23 @@ static int diff_delta_is_binary_by_attr(
delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
delta->binary = 0;
- return 0;
+ return true;
}
+ return false;
+}
+
+static int diff_delta_is_binary_by_attr(
+ diff_context *ctxt, git_diff_patch *patch)
+{
+ int error = 0, mirror_new;
+ git_diff_delta *delta = patch->delta;
+
+ delta->binary = -1;
+
+ if (diff_delta_is_binary_forced(ctxt, delta))
+ return 0;
+
/* check diff attribute +, -, or 0 */
if (update_file_is_binary_by_attr(ctxt->repo, &delta->old_file) < 0)
return -1;
@@ -137,13 +152,8 @@ static int diff_delta_is_binary_by_content(
git_diff_file *file,
const git_map *map)
{
- /* check if user is forcing us to text diff these files */
- if (ctxt->opts && (ctxt->opts->flags & GIT_DIFF_FORCE_TEXT) != 0) {
- delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
- delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
- delta->binary = 0;
+ if (diff_delta_is_binary_forced(ctxt, delta))
return 0;
- }
if ((file->flags & KNOWN_BINARY_FLAGS) == 0) {
const git_buf search = { map->data, 0, min(map->len, 4000) };