summaryrefslogtreecommitdiff
path: root/src/diff.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-11-06 16:16:46 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-11-07 08:33:27 +0100
commit62a617dc683c1e73eebd0e1b6209f76748e67ed4 (patch)
tree5893fe2b801d96825582d8a461b50e80f4a2a43a /src/diff.c
parentf1a7906fdf0657fba88449bdab07237847f36670 (diff)
downloadlibgit2-62a617dc683c1e73eebd0e1b6209f76748e67ed4.tar.gz
iterator: submodules are determined by an index or treecmn/submodule-and-dir
We cannot know from looking at .gitmodules whether a directory is a submodule or not. We need the index or tree we are comparing against to tell us. Otherwise we have to assume the entry in .gitmodules is stale or otherwise invalid. Thus we pass the index of the repository into the workdir iterator, even if we do not want to compare against it. This follows what git does, which even for `git diff <tree>`, it will consider staged submodules as such.
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/diff.c b/src/diff.c
index 375d4cb13..89b3b77f3 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1214,7 +1214,7 @@ int git_diff_index_to_workdir(
DIFF_FROM_ITERATORS(
git_iterator_for_index(&a, index, 0, pfx, pfx),
git_iterator_for_workdir(
- &b, repo, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
+ &b, repo, index, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
);
if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX))
@@ -1230,15 +1230,20 @@ int git_diff_tree_to_workdir(
const git_diff_options *opts)
{
int error = 0;
+ git_index *index;
assert(diff && repo);
+ if ((error = git_repository_index(&index, repo)))
+ return error;
+
DIFF_FROM_ITERATORS(
git_iterator_for_tree(&a, old_tree, 0, pfx, pfx),
git_iterator_for_workdir(
- &b, repo, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
+ &b, repo, index, old_tree, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
);
+ git_index_free(index);
return error;
}