Commit 3a3deea80bb6555706f58006bdee8e878b0fd651

Russell Belfer 2012-09-06T15:45:50

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.

diff --git a/src/diff_output.c b/src/diff_output.c
index e2ca8cf..6ff880e 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 */