diff options
author | Russell Belfer <rb@github.com> | 2012-11-14 23:29:48 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-11-14 23:29:48 -0800 |
commit | bbe6dbec81d2050fb52b600bc27e2dacdc780e77 (patch) | |
tree | 61f442146ed5b98352016f4ecec3ac4736e10c8c /src/diff.c | |
parent | bad68c0a998116685ad75cab84210004dd2c5be1 (diff) | |
download | libgit2-bbe6dbec81d2050fb52b600bc27e2dacdc780e77.tar.gz |
Add explicit git_index ptr to diff and checkout
A number of diff APIs and the `git_checkout_index` API take a
`git_repository` object an operate on the index. This updates
them to take a `git_index` pointer explicitly and only fall back
on the `git_repository` index if the index input is NULL. This
makes it easier to operate on a temporary index.
Diffstat (limited to 'src/diff.c')
-rw-r--r-- | src/diff.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/diff.c b/src/diff.c index e6634e6d2..728e23712 100644 --- a/src/diff.c +++ b/src/diff.c @@ -753,15 +753,13 @@ fail: } -#define DIFF_FROM_ITERATORS(SETUP, MAKE_FIRST, MAKE_SECOND) \ - int error; \ +#define DIFF_FROM_ITERATORS(MAKE_FIRST, MAKE_SECOND) do { \ git_iterator *a = NULL, *b = NULL; \ char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; \ - SETUP; \ if (!(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \ error = diff_from_iterators(diff, repo, a, b, opts); \ git__free(pfx); git_iterator_free(a); git_iterator_free(b); \ - return error + } while (0) int git_diff_tree_to_tree( git_diff_list **diff, @@ -770,49 +768,59 @@ int git_diff_tree_to_tree( git_tree *new_tree, const git_diff_options *opts) { + int error = 0; + + assert(diff && repo); + DIFF_FROM_ITERATORS( - assert(repo && old_tree && new_tree && diff), git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx), git_iterator_for_tree_range(&b, repo, new_tree, pfx, pfx) ); -} -int git_diff__tree_to_index( - git_diff_list **diff, - git_tree *tree, - git_index *index, - const git_diff_options *opts) -{ - DIFF_FROM_ITERATORS( - git_repository *repo = git_index_owner(index), - git_iterator_for_index_range(&a, index, pfx, pfx), - git_iterator_for_tree_range(&b, repo, tree, pfx, pfx) - ); + return error; } int git_diff_index_to_tree( git_diff_list **diff, git_repository *repo, git_tree *old_tree, + git_index *index, const git_diff_options *opts) { + int error = 0; + + assert(diff && repo); + + if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0) + return error; + DIFF_FROM_ITERATORS( - assert(repo && diff), git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx), - git_iterator_for_repo_index_range(&b, repo, pfx, pfx) + git_iterator_for_index_range(&b, index, pfx, pfx) ); + + return error; } int git_diff_workdir_to_index( git_diff_list **diff, git_repository *repo, + git_index *index, const git_diff_options *opts) { + int error = 0; + + assert(diff && repo); + + if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0) + return error; + DIFF_FROM_ITERATORS( - assert(repo && diff), - git_iterator_for_repo_index_range(&a, repo, pfx, pfx), + git_iterator_for_index_range(&a, index, pfx, pfx), git_iterator_for_workdir_range(&b, repo, pfx, pfx) ); + + return error; } @@ -822,9 +830,14 @@ int git_diff_workdir_to_tree( git_tree *old_tree, const git_diff_options *opts) { + int error = 0; + + assert(diff && repo); + DIFF_FROM_ITERATORS( - assert(repo && diff), git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx), git_iterator_for_workdir_range(&b, repo, pfx, pfx) ); + + return error; } |