summaryrefslogtreecommitdiff
path: root/src/diff_output.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-01-15 09:24:17 -0800
committerRussell Belfer <rb@github.com>2013-02-11 14:45:46 -0800
commitc2907575ec050d4cbc667544f7e6114e09b7b123 (patch)
tree07040442645f8183617e02674e827eac9f98fe29 /src/diff_output.c
parent40a605104c2060c2bc5a08dfb62cafe473baeb21 (diff)
downloadlibgit2-c2907575ec050d4cbc667544f7e6114e09b7b123.tar.gz
Add FORCE_TEXT check into git_diff_blobs code path
`git_diff_blobs` and `git_diff_blob_to_buffer` skip the step where we check file attributes because they don't have a filename associated with the data. Unfortunately, this meant they were also skipping the check for the GIT_DIFF_FORCE_TEXT option and so you could not force a diff of an apparent binary file. This adds the force text check into their code path.
Diffstat (limited to 'src/diff_output.c')
-rw-r--r--src/diff_output.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/diff_output.c b/src/diff_output.c
index c2c259161..2e0be63c2 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -137,15 +137,22 @@ static int diff_delta_is_binary_by_content(
git_diff_file *file,
const git_map *map)
{
- const git_buf search = { map->data, 0, min(map->len, 4000) };
-
- GIT_UNUSED(ctxt);
+ /* 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;
+ return 0;
+ }
if ((file->flags & KNOWN_BINARY_FLAGS) == 0) {
+ const git_buf search = { map->data, 0, min(map->len, 4000) };
+
/* TODO: provide encoding / binary detection callbacks that can
* be UTF-8 aware, etc. For now, instead of trying to be smart,
* let's just use the simple NUL-byte detection that core git uses.
*/
+
/* previously was: if (git_buf_text_is_binary(&search)) */
if (git_buf_text_contains_nul(&search))
file->flags |= GIT_DIFF_FILE_BINARY;