From 3a3deea80bb6555706f58006bdee8e878b0fd651 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 6 Sep 2012 15:45:50 -0700 Subject: [PATCH] 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. --- src/diff_output.c | 13 +++++++++++-- 1 file 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 */