summaryrefslogtreecommitdiff
path: root/src/diff_output.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-09-06 15:45:50 -0700
committerRussell Belfer <rb@github.com>2012-09-06 15:45:50 -0700
commit3a3deea80bb6555706f58006bdee8e878b0fd651 (patch)
tree34eccce16579a37a8fabf989002f0232e0d625ce /src/diff_output.c
parent60b9d3fcef04a6beb0ad4df225ada058afabf0b9 (diff)
downloadlibgit2-3a3deea80bb6555706f58006bdee8e878b0fd651.tar.gz
Clean up blob diff path
Previously when diffing blobs, the diff code just ran with a NULL repository object. Of course, that's not necessary and the test for a NULL repo was confusing. This makes the blob diff run with the repo that contains the blobs and clarifies the test that it is possible to be diffing data where the path is unknown.
Diffstat (limited to 'src/diff_output.c')
-rw-r--r--src/diff_output.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/diff_output.c b/src/diff_output.c
index e2ca8cf3e..6ff880e95 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -151,7 +151,8 @@ static int update_file_is_binary_by_attr(
{
const char *value;
- if (!repo)
+ /* because of blob diffs, cannot assume path is set */
+ if (!file->path || !strlen(file->path))
return 0;
if (git_attr_get(&value, repo, 0, file->path, "diff") < 0)
@@ -1028,6 +1029,7 @@ int git_diff_blobs(
diff_delta_context ctxt;
git_diff_delta delta;
git_blob *new, *old;
+ git_repository *repo;
new = new_blob;
old = old_blob;
@@ -1038,8 +1040,15 @@ int git_diff_blobs(
new = swap;
}
+ if (new)
+ repo = git_object_owner((git_object *)new);
+ else if (old)
+ repo = git_object_owner((git_object *)old);
+ else
+ repo = NULL;
+
diff_delta_init_context(
- &ctxt, NULL, options, GIT_ITERATOR_TREE, GIT_ITERATOR_TREE);
+ &ctxt, repo, options, GIT_ITERATOR_TREE, GIT_ITERATOR_TREE);
/* populate a "fake" delta record */