Commit 5735bf5e by Russell Belfer

Fix diff API to better parameter order

The diff API is not in the parameter order one would expect from
other libgit2 APIs.  This fixes that.
parent 5a36f127
...@@ -317,52 +317,52 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff); ...@@ -317,52 +317,52 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
* *
* This is equivalent to `git diff <treeish> <treeish>` * This is equivalent to `git diff <treeish> <treeish>`
* *
* @param diff Output pointer to a git_diff_list pointer to be allocated.
* @param repo The repository containing the trees. * @param repo The repository containing the trees.
* @param opts Structure with options to influence diff or NULL for defaults.
* @param old_tree A git_tree object to diff from. * @param old_tree A git_tree object to diff from.
* @param new_tree A git_tree object to diff to. * @param new_tree A git_tree object to diff to.
* @param diff A pointer to a git_diff_list pointer that will be allocated. * @param opts Structure with options to influence diff or NULL for defaults.
*/ */
GIT_EXTERN(int) git_diff_tree_to_tree( GIT_EXTERN(int) git_diff_tree_to_tree(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old_tree, git_tree *old_tree,
git_tree *new_tree, git_tree *new_tree,
git_diff_list **diff); const git_diff_options *opts); /**< can be NULL for defaults */
/** /**
* Compute a difference between a tree and the index. * Compute a difference between a tree and the repository index.
* *
* This is equivalent to `git diff --cached <treeish>` or if you pass * This is equivalent to `git diff --cached <treeish>` or if you pass
* the HEAD tree, then like `git diff --cached`. * the HEAD tree, then like `git diff --cached`.
* *
* @param diff Output pointer to a git_diff_list pointer to be allocated.
* @param repo The repository containing the tree and index. * @param repo The repository containing the tree and index.
* @param opts Structure with options to influence diff or NULL for defaults.
* @param old_tree A git_tree object to diff from. * @param old_tree A git_tree object to diff from.
* @param diff A pointer to a git_diff_list pointer that will be allocated. * @param opts Structure with options to influence diff or NULL for defaults.
*/ */
GIT_EXTERN(int) git_diff_index_to_tree( GIT_EXTERN(int) git_diff_index_to_tree(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old_tree, git_tree *old_tree,
git_diff_list **diff); const git_diff_options *opts); /**< can be NULL for defaults */
/** /**
* Compute a difference between the working directory and the index. * Compute a difference between the working directory and the repository index.
* *
* This matches the `git diff` command. See the note below on * This matches the `git diff` command. See the note below on
* `git_diff_workdir_to_tree` for a discussion of the difference between * `git_diff_workdir_to_tree` for a discussion of the difference between
* `git diff` and `git diff HEAD` and how to emulate a `git diff <treeish>` * `git diff` and `git diff HEAD` and how to emulate a `git diff <treeish>`
* using libgit2. * using libgit2.
* *
* @param diff Output pointer to a git_diff_list pointer to be allocated.
* @param repo The repository. * @param repo The repository.
* @param opts Structure with options to influence diff or NULL for defaults. * @param opts Structure with options to influence diff or NULL for defaults.
* @param diff A pointer to a git_diff_list pointer that will be allocated.
*/ */
GIT_EXTERN(int) git_diff_workdir_to_index( GIT_EXTERN(int) git_diff_workdir_to_index(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */ const git_diff_options *opts); /**< can be NULL for defaults */
git_diff_list **diff);
/** /**
* Compute a difference between the working directory and a tree. * Compute a difference between the working directory and a tree.
...@@ -386,16 +386,16 @@ GIT_EXTERN(int) git_diff_workdir_to_index( ...@@ -386,16 +386,16 @@ GIT_EXTERN(int) git_diff_workdir_to_index(
* The tree-to-workdir diff for that file is 'modified', but core git would * The tree-to-workdir diff for that file is 'modified', but core git would
* show status 'deleted' since there is a pending deletion in the index. * show status 'deleted' since there is a pending deletion in the index.
* *
* @param diff A pointer to a git_diff_list pointer that will be allocated.
* @param repo The repository containing the tree. * @param repo The repository containing the tree.
* @param opts Structure with options to influence diff or NULL for defaults.
* @param old_tree A git_tree object to diff from. * @param old_tree A git_tree object to diff from.
* @param diff A pointer to a git_diff_list pointer that will be allocated. * @param opts Structure with options to influence diff or NULL for defaults.
*/ */
GIT_EXTERN(int) git_diff_workdir_to_tree( GIT_EXTERN(int) git_diff_workdir_to_tree(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old_tree, git_tree *old_tree,
git_diff_list **diff); const git_diff_options *opts); /**< can be NULL for defaults */
/** /**
* Merge one diff list into another. * Merge one diff list into another.
......
...@@ -625,7 +625,7 @@ int git_checkout_index( ...@@ -625,7 +625,7 @@ int git_checkout_index(
if (opts && opts->paths.count > 0) if (opts && opts->paths.count > 0)
diff_opts.pathspec = opts->paths; diff_opts.pathspec = opts->paths;
if ((error = git_diff_workdir_to_index(repo, &diff_opts, &diff)) < 0) if ((error = git_diff_workdir_to_index(&diff, repo, &diff_opts)) < 0)
goto cleanup; goto cleanup;
if ((error = git_buf_puts(&workdir, git_repository_workdir(repo))) < 0) if ((error = git_buf_puts(&workdir, git_repository_workdir(repo))) < 0)
......
...@@ -568,11 +568,11 @@ static int diff_list_init_from_iterators( ...@@ -568,11 +568,11 @@ static int diff_list_init_from_iterators(
} }
static int diff_from_iterators( static int diff_from_iterators(
git_diff_list **diff_ptr,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */
git_iterator *old_iter, git_iterator *old_iter,
git_iterator *new_iter, git_iterator *new_iter,
git_diff_list **diff_ptr) const git_diff_options *opts)
{ {
int error = 0; int error = 0;
const git_index_entry *oitem, *nitem; const git_index_entry *oitem, *nitem;
...@@ -747,108 +747,71 @@ fail: ...@@ -747,108 +747,71 @@ fail:
error = -1; error = -1;
} }
git_iterator_free(old_iter);
git_iterator_free(new_iter);
git_buf_free(&ignore_prefix); git_buf_free(&ignore_prefix);
return error; return error;
} }
#define DIFF_FROM_ITERATORS(SETUP, MAKE_FIRST, MAKE_SECOND) \
int error; \
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
int git_diff_tree_to_tree( int git_diff_tree_to_tree(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old_tree, git_tree *old_tree,
git_tree *new_tree, git_tree *new_tree,
git_diff_list **diff) const git_diff_options *opts)
{ {
git_iterator *a = NULL, *b = NULL; DIFF_FROM_ITERATORS(
char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; assert(repo && old_tree && new_tree && diff),
git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx),
assert(repo && old_tree && new_tree && diff); git_iterator_for_tree_range(&b, repo, new_tree, pfx, pfx)
);
if (git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx) < 0 ||
git_iterator_for_tree_range(&b, repo, new_tree, pfx, pfx) < 0)
return -1;
git__free(pfx);
return diff_from_iterators(repo, opts, a, b, diff);
} }
int git_diff_index_to_tree( int git_diff_index_to_tree(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts,
git_tree *old_tree, git_tree *old_tree,
git_diff_list **diff) const git_diff_options *opts)
{ {
git_iterator *a = NULL, *b = NULL; DIFF_FROM_ITERATORS(
char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; assert(repo && diff),
git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx),
assert(repo && diff); git_iterator_for_index_range(&b, repo, pfx, pfx)
);
if (git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx) < 0 ||
git_iterator_for_index_range(&b, repo, pfx, pfx) < 0)
goto on_error;
git__free(pfx);
return diff_from_iterators(repo, opts, a, b, diff);
on_error:
git__free(pfx);
git_iterator_free(a);
return -1;
} }
int git_diff_workdir_to_index( int git_diff_workdir_to_index(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, const git_diff_options *opts)
git_diff_list **diff)
{ {
int error; DIFF_FROM_ITERATORS(
git_iterator *a = NULL, *b = NULL; assert(repo && diff),
char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; git_iterator_for_index_range(&a, repo, pfx, pfx),
git_iterator_for_workdir_range(&b, repo, pfx, pfx)
assert(repo && diff); );
if ((error = git_iterator_for_index_range(&a, repo, pfx, pfx)) < 0 ||
(error = git_iterator_for_workdir_range(&b, repo, pfx, pfx)) < 0)
goto on_error;
git__free(pfx);
return diff_from_iterators(repo, opts, a, b, diff);
on_error:
git__free(pfx);
git_iterator_free(a);
return error;
} }
int git_diff_workdir_to_tree( int git_diff_workdir_to_tree(
git_diff_list **diff,
git_repository *repo, git_repository *repo,
const git_diff_options *opts, git_tree *old_tree,
git_tree *tree, const git_diff_options *opts)
git_diff_list **diff)
{ {
int error; DIFF_FROM_ITERATORS(
git_iterator *a = NULL, *b = NULL; assert(repo && diff),
char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; git_iterator_for_tree_range(&a, repo, old_tree, pfx, pfx),
git_iterator_for_workdir_range(&b, repo, pfx, pfx)
assert(repo && tree && diff); );
if ((error = git_iterator_for_tree_range(&a, repo, tree, pfx, pfx)) < 0 ||
(error = git_iterator_for_workdir_range(&b, repo, pfx, pfx)) < 0)
goto on_error;
git__free(pfx);
return diff_from_iterators(repo, opts, a, b, diff);
on_error:
git__free(pfx);
git_iterator_free(a);
return error;
} }
...@@ -250,7 +250,7 @@ static int build_untracked_tree( ...@@ -250,7 +250,7 @@ static int build_untracked_tree(
if (git_commit_tree(&i_tree, i_commit) < 0) if (git_commit_tree(&i_tree, i_commit) < 0)
goto cleanup; goto cleanup;
if (git_diff_workdir_to_tree(git_index_owner(index), &opts, i_tree, &diff) < 0) if (git_diff_workdir_to_tree(&diff, git_index_owner(index), i_tree, &opts) < 0)
goto cleanup; goto cleanup;
if (git_diff_foreach(diff, &data, update_index_cb, NULL, NULL) < 0) if (git_diff_foreach(diff, &data, update_index_cb, NULL, NULL) < 0)
...@@ -312,6 +312,7 @@ static int build_workdir_tree( ...@@ -312,6 +312,7 @@ static int build_workdir_tree(
git_index *index, git_index *index,
git_commit *b_commit) git_commit *b_commit)
{ {
git_repository *repo = git_index_owner(index);
git_tree *b_tree = NULL; git_tree *b_tree = NULL;
git_diff_list *diff = NULL, *diff2 = NULL; git_diff_list *diff = NULL, *diff2 = NULL;
git_diff_options opts = {0}; git_diff_options opts = {0};
...@@ -321,10 +322,10 @@ static int build_workdir_tree( ...@@ -321,10 +322,10 @@ static int build_workdir_tree(
if (git_commit_tree(&b_tree, b_commit) < 0) if (git_commit_tree(&b_tree, b_commit) < 0)
goto cleanup; goto cleanup;
if (git_diff_index_to_tree(git_index_owner(index), &opts, b_tree, &diff) < 0) if (git_diff_index_to_tree(&diff, repo, b_tree, &opts) < 0)
goto cleanup; goto cleanup;
if (git_diff_workdir_to_index(git_index_owner(index), &opts, &diff2) < 0) if (git_diff_workdir_to_index(&diff2, repo, &opts) < 0)
goto cleanup; goto cleanup;
if (git_diff_merge(diff, diff2) < 0) if (git_diff_merge(diff, diff2) < 0)
......
...@@ -142,11 +142,11 @@ int git_status_foreach_ext( ...@@ -142,11 +142,11 @@ int git_status_foreach_ext(
/* TODO: support EXCLUDE_SUBMODULES flag */ /* TODO: support EXCLUDE_SUBMODULES flag */
if (show != GIT_STATUS_SHOW_WORKDIR_ONLY && if (show != GIT_STATUS_SHOW_WORKDIR_ONLY &&
(err = git_diff_index_to_tree(repo, &diffopt, head, &idx2head)) < 0) (err = git_diff_index_to_tree(&idx2head, repo, head, &diffopt)) < 0)
goto cleanup; goto cleanup;
if (show != GIT_STATUS_SHOW_INDEX_ONLY && if (show != GIT_STATUS_SHOW_INDEX_ONLY &&
(err = git_diff_workdir_to_index(repo, &diffopt, &wd2idx)) < 0) (err = git_diff_workdir_to_index(&wd2idx, repo, &diffopt)) < 0)
goto cleanup; goto cleanup;
usercb.cb = cb; usercb.cb = cb;
......
...@@ -1455,7 +1455,7 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm) ...@@ -1455,7 +1455,7 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm)
if (sm->ignore == GIT_SUBMODULE_IGNORE_NONE) if (sm->ignore == GIT_SUBMODULE_IGNORE_NONE)
opt.flags |= GIT_DIFF_INCLUDE_UNTRACKED; opt.flags |= GIT_DIFF_INCLUDE_UNTRACKED;
error = git_diff_index_to_tree(sm_repo, &opt, sm_head, &diff); error = git_diff_index_to_tree(&diff, sm_repo, sm_head, &opt);
if (!error) { if (!error) {
if (git_diff_num_deltas(diff) > 0) if (git_diff_num_deltas(diff) > 0)
...@@ -1472,7 +1472,7 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm) ...@@ -1472,7 +1472,7 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm)
/* perform index-to-workdir diff on submodule */ /* perform index-to-workdir diff on submodule */
error = git_diff_workdir_to_index(sm_repo, &opt, &diff); error = git_diff_workdir_to_index(&diff, sm_repo, &opt);
if (!error) { if (!error) {
size_t untracked = size_t untracked =
......
...@@ -16,7 +16,7 @@ void test_diff_diffiter__create(void) ...@@ -16,7 +16,7 @@ void test_diff_diffiter__create(void)
git_diff_list *diff; git_diff_list *diff;
size_t d, num_d; size_t d, num_d;
cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) { for (d = 0; d < num_d; ++d) {
...@@ -34,7 +34,7 @@ void test_diff_diffiter__iterate_files(void) ...@@ -34,7 +34,7 @@ void test_diff_diffiter__iterate_files(void)
size_t d, num_d; size_t d, num_d;
int count = 0; int count = 0;
cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
cl_assert_equal_i(6, (int)num_d); cl_assert_equal_i(6, (int)num_d);
...@@ -57,7 +57,7 @@ void test_diff_diffiter__iterate_files_2(void) ...@@ -57,7 +57,7 @@ void test_diff_diffiter__iterate_files_2(void)
size_t d, num_d; size_t d, num_d;
int count = 0; int count = 0;
cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
cl_assert_equal_i(8, (int)num_d); cl_assert_equal_i(8, (int)num_d);
...@@ -85,7 +85,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) ...@@ -85,7 +85,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void)
opts.interhunk_lines = 1; opts.interhunk_lines = 1;
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
...@@ -138,7 +138,7 @@ void test_diff_diffiter__max_size_threshold(void) ...@@ -138,7 +138,7 @@ void test_diff_diffiter__max_size_threshold(void)
opts.interhunk_lines = 1; opts.interhunk_lines = 1;
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) { for (d = 0; d < num_d; ++d) {
...@@ -173,7 +173,7 @@ void test_diff_diffiter__max_size_threshold(void) ...@@ -173,7 +173,7 @@ void test_diff_diffiter__max_size_threshold(void)
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
opts.max_size = 50; /* treat anything over 50 bytes as binary! */ opts.max_size = 50; /* treat anything over 50 bytes as binary! */
cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) { for (d = 0; d < num_d; ++d) {
...@@ -216,7 +216,7 @@ void test_diff_diffiter__iterate_all(void) ...@@ -216,7 +216,7 @@ void test_diff_diffiter__iterate_all(void)
opts.interhunk_lines = 1; opts.interhunk_lines = 1;
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) { for (d = 0; d < num_d; ++d) {
...@@ -292,7 +292,7 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) ...@@ -292,7 +292,7 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void)
opts.interhunk_lines = 1; opts.interhunk_lines = 1;
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
...@@ -419,7 +419,7 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) ...@@ -419,7 +419,7 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void)
git_diff_list *diff; git_diff_list *diff;
size_t d, num_d; size_t d, num_d;
cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
cl_assert_equal_i(8, (int)num_d); cl_assert_equal_i(8, (int)num_d);
......
...@@ -32,7 +32,7 @@ void test_diff_index__0(void) ...@@ -32,7 +32,7 @@ void test_diff_index__0(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_index_to_tree(g_repo, &opts, a, &diff)); cl_git_pass(git_diff_index_to_tree(&diff, g_repo, a, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -60,7 +60,7 @@ void test_diff_index__0(void) ...@@ -60,7 +60,7 @@ void test_diff_index__0(void)
diff = NULL; diff = NULL;
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_index_to_tree(g_repo, &opts, b, &diff)); cl_git_pass(git_diff_index_to_tree(&diff, g_repo, b, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -125,7 +125,7 @@ void test_diff_index__1(void) ...@@ -125,7 +125,7 @@ void test_diff_index__1(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_index_to_tree(g_repo, &opts, a, &diff)); cl_git_pass(git_diff_index_to_tree(&diff, g_repo, a, &opts));
cl_assert_equal_i( cl_assert_equal_i(
GIT_EUSER, GIT_EUSER,
......
...@@ -88,7 +88,7 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void) ...@@ -88,7 +88,7 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
one = resolve_commit_oid_to_tree(g_repo, one_sha); one = resolve_commit_oid_to_tree(g_repo, one_sha);
another = resolve_commit_oid_to_tree(g_repo, another_sha); another = resolve_commit_oid_to_tree(g_repo, another_sha);
cl_git_pass(git_diff_tree_to_tree(g_repo, NULL, one, another, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
cl_git_pass(git_diff_print_patch(diff, NULL, check_removal_cb)); cl_git_pass(git_diff_print_patch(diff, NULL, check_removal_cb));
...@@ -111,7 +111,7 @@ void test_diff_patch__to_string(void) ...@@ -111,7 +111,7 @@ void test_diff_patch__to_string(void)
one = resolve_commit_oid_to_tree(g_repo, one_sha); one = resolve_commit_oid_to_tree(g_repo, one_sha);
another = resolve_commit_oid_to_tree(g_repo, another_sha); another = resolve_commit_oid_to_tree(g_repo, another_sha);
cl_git_pass(git_diff_tree_to_tree(g_repo, NULL, one, another, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
cl_assert_equal_i(1, git_diff_num_deltas(diff)); cl_assert_equal_i(1, git_diff_num_deltas(diff));
......
...@@ -47,7 +47,7 @@ void test_diff_rename__match_oid(void) ...@@ -47,7 +47,7 @@ void test_diff_rename__match_oid(void)
diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED; diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
cl_git_pass(git_diff_tree_to_tree( cl_git_pass(git_diff_tree_to_tree(
g_repo, &diffopts, old_tree, new_tree, &diff)); &diff, g_repo, old_tree, new_tree, &diffopts));
/* git diff --no-renames \ /* git diff --no-renames \
* 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \ * 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
...@@ -79,7 +79,7 @@ void test_diff_rename__match_oid(void) ...@@ -79,7 +79,7 @@ void test_diff_rename__match_oid(void)
git_diff_list_free(diff); git_diff_list_free(diff);
cl_git_pass(git_diff_tree_to_tree( cl_git_pass(git_diff_tree_to_tree(
g_repo, &diffopts, old_tree, new_tree, &diff)); &diff, g_repo, old_tree, new_tree, &diffopts));
/* git diff --find-copies-harder \ /* git diff --find-copies-harder \
* 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \ * 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
......
...@@ -34,7 +34,7 @@ void test_diff_tree__0(void) ...@@ -34,7 +34,7 @@ void test_diff_tree__0(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, a, b, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -56,7 +56,7 @@ void test_diff_tree__0(void) ...@@ -56,7 +56,7 @@ void test_diff_tree__0(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, c, b, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, b, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -141,9 +141,9 @@ void test_diff_tree__options(void) ...@@ -141,9 +141,9 @@ void test_diff_tree__options(void)
opts = test_options[i]; opts = test_options[i];
if (test_ab_or_cd[i] == 0) if (test_ab_or_cd[i] == 0)
cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, a, b, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
else else
cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, c, d, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, d, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &actual, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &actual, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -187,7 +187,7 @@ void test_diff_tree__bare(void) ...@@ -187,7 +187,7 @@ void test_diff_tree__bare(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, a, b, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -225,9 +225,9 @@ void test_diff_tree__merge(void) ...@@ -225,9 +225,9 @@ void test_diff_tree__merge(void)
cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL); cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL);
cl_assert((c = resolve_commit_oid_to_tree(g_repo, c_commit)) != NULL); cl_assert((c = resolve_commit_oid_to_tree(g_repo, c_commit)) != NULL);
cl_git_pass(git_diff_tree_to_tree(g_repo, NULL, a, b, &diff1)); cl_git_pass(git_diff_tree_to_tree(&diff1, g_repo, a, b, NULL));
cl_git_pass(git_diff_tree_to_tree(g_repo, NULL, c, b, &diff2)); cl_git_pass(git_diff_tree_to_tree(&diff2, g_repo, c, b, NULL));
git_tree_free(a); git_tree_free(a);
git_tree_free(b); git_tree_free(b);
...@@ -279,7 +279,7 @@ void test_diff_tree__larger_hunks(void) ...@@ -279,7 +279,7 @@ void test_diff_tree__larger_hunks(void)
opts.context_lines = 1; opts.context_lines = 1;
opts.interhunk_lines = 0; opts.interhunk_lines = 0;
cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, a, b, &diff)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
num_d = git_diff_num_deltas(diff); num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) { for (d = 0; d < num_d; ++d) {
......
...@@ -26,7 +26,7 @@ void test_diff_workdir__to_index(void) ...@@ -26,7 +26,7 @@ void test_diff_workdir__to_index(void)
opts.interhunk_lines = 1; opts.interhunk_lines = 1;
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -94,7 +94,7 @@ void test_diff_workdir__to_tree(void) ...@@ -94,7 +94,7 @@ void test_diff_workdir__to_tree(void)
* The results are documented at the bottom of this file in the * The results are documented at the bottom of this file in the
* long comment entitled "PREPARATION OF TEST DATA". * long comment entitled "PREPARATION OF TEST DATA".
*/ */
cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, a, &diff)); cl_git_pass(git_diff_workdir_to_tree(&diff, g_repo, a, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -127,8 +127,8 @@ void test_diff_workdir__to_tree(void) ...@@ -127,8 +127,8 @@ void test_diff_workdir__to_tree(void)
* a workdir to tree diff (even though it is not really). This is what * a workdir to tree diff (even though it is not really). This is what
* you would get from "git diff --name-status 26a125ee1bf" * you would get from "git diff --name-status 26a125ee1bf"
*/ */
cl_git_pass(git_diff_index_to_tree(g_repo, &opts, a, &diff)); cl_git_pass(git_diff_index_to_tree(&diff, g_repo, a, &opts));
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff2)); cl_git_pass(git_diff_workdir_to_index(&diff2, g_repo, &opts));
cl_git_pass(git_diff_merge(diff, diff2)); cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2); git_diff_list_free(diff2);
...@@ -164,8 +164,8 @@ void test_diff_workdir__to_tree(void) ...@@ -164,8 +164,8 @@ void test_diff_workdir__to_tree(void)
/* Again, emulating "git diff <sha>" for testing purposes using /* Again, emulating "git diff <sha>" for testing purposes using
* "git diff --name-status 0017bd4ab1ec3" instead. * "git diff --name-status 0017bd4ab1ec3" instead.
*/ */
cl_git_pass(git_diff_index_to_tree(g_repo, &opts, b, &diff)); cl_git_pass(git_diff_index_to_tree(&diff, g_repo, b, &opts));
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff2)); cl_git_pass(git_diff_workdir_to_index(&diff2, g_repo, &opts));
cl_git_pass(git_diff_merge(diff, diff2)); cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2); git_diff_list_free(diff2);
...@@ -216,7 +216,7 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -216,7 +216,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
opts.pathspec.strings = &pathspec; opts.pathspec.strings = &pathspec;
opts.pathspec.count = 1; opts.pathspec.count = 1;
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -239,7 +239,7 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -239,7 +239,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
pathspec = "modified_file"; pathspec = "modified_file";
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -262,7 +262,7 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -262,7 +262,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
pathspec = "subdir"; pathspec = "subdir";
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -285,7 +285,7 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -285,7 +285,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
pathspec = "*_deleted"; pathspec = "*_deleted";
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -324,7 +324,7 @@ void test_diff_workdir__filemode_changes(void) ...@@ -324,7 +324,7 @@ void test_diff_workdir__filemode_changes(void)
/* test once with no mods */ /* test once with no mods */
cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, NULL));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -347,7 +347,7 @@ void test_diff_workdir__filemode_changes(void) ...@@ -347,7 +347,7 @@ void test_diff_workdir__filemode_changes(void)
cl_assert(cl_toggle_filemode("issue_592/a.txt")); cl_assert(cl_toggle_filemode("issue_592/a.txt"));
cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, NULL));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -386,7 +386,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void) ...@@ -386,7 +386,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
/* test once with no mods */ /* test once with no mods */
cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, NULL));
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
...@@ -402,7 +402,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void) ...@@ -402,7 +402,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
cl_assert(cl_toggle_filemode("issue_592/a.txt")); cl_assert(cl_toggle_filemode("issue_592/a.txt"));
cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, NULL));
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
...@@ -442,8 +442,8 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void) ...@@ -442,8 +442,8 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
opts.pathspec.strings = &pathspec; opts.pathspec.strings = &pathspec;
opts.pathspec.count = 1; opts.pathspec.count = 1;
cl_git_pass(git_diff_index_to_tree(g_repo, &opts, tree, &diff_i2t)); cl_git_pass(git_diff_index_to_tree(&diff_i2t, g_repo, tree, &opts));
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff_w2i)); cl_git_pass(git_diff_workdir_to_index(&diff_w2i, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -529,7 +529,7 @@ void test_diff_workdir__eof_newline_changes(void) ...@@ -529,7 +529,7 @@ void test_diff_workdir__eof_newline_changes(void)
opts.pathspec.strings = &pathspec; opts.pathspec.strings = &pathspec;
opts.pathspec.count = 1; opts.pathspec.count = 1;
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -556,7 +556,7 @@ void test_diff_workdir__eof_newline_changes(void) ...@@ -556,7 +556,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_git_append2file("status/current_file", "\n"); cl_git_append2file("status/current_file", "\n");
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -583,7 +583,7 @@ void test_diff_workdir__eof_newline_changes(void) ...@@ -583,7 +583,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_git_rewritefile("status/current_file", "current_file"); cl_git_rewritefile("status/current_file", "current_file");
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
for (use_iterator = 0; use_iterator <= 1; use_iterator++) { for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
...@@ -699,13 +699,13 @@ void test_diff_workdir__larger_hunks(void) ...@@ -699,13 +699,13 @@ void test_diff_workdir__larger_hunks(void)
/* okay, this is a bit silly, but oh well */ /* okay, this is a bit silly, but oh well */
switch (i) { switch (i) {
case 0: case 0:
cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_git_pass(git_diff_workdir_to_index(&diff, g_repo, &opts));
break; break;
case 1: case 1:
cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, a, &diff)); cl_git_pass(git_diff_workdir_to_tree(&diff, g_repo, a, &opts));
break; break;
case 2: case 2:
cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, b, &diff)); cl_git_pass(git_diff_workdir_to_tree(&diff, g_repo, b, &opts));
break; break;
} }
...@@ -784,7 +784,7 @@ void test_diff_workdir__submodules(void) ...@@ -784,7 +784,7 @@ void test_diff_workdir__submodules(void)
GIT_DIFF_RECURSE_UNTRACKED_DIRS | GIT_DIFF_RECURSE_UNTRACKED_DIRS |
GIT_DIFF_INCLUDE_UNTRACKED_CONTENT; GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, a, &diff)); cl_git_pass(git_diff_workdir_to_tree(&diff, g_repo, a, &opts));
/* diff_print(stderr, diff); */ /* diff_print(stderr, diff); */
...@@ -828,10 +828,13 @@ void test_diff_workdir__cannot_diff_against_a_bare_repository(void) ...@@ -828,10 +828,13 @@ void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
g_repo = cl_git_sandbox_init("testrepo.git"); g_repo = cl_git_sandbox_init("testrepo.git");
cl_assert_equal_i(GIT_EBAREREPO, git_diff_workdir_to_index(g_repo, &opts, &diff)); cl_assert_equal_i(
GIT_EBAREREPO, git_diff_workdir_to_index(&diff, g_repo, &opts));
cl_git_pass(git_repository_head_tree(&tree, g_repo)); cl_git_pass(git_repository_head_tree(&tree, g_repo));
cl_assert_equal_i(GIT_EBAREREPO, git_diff_workdir_to_tree(g_repo, &opts, tree, &diff));
cl_assert_equal_i(
GIT_EBAREREPO, git_diff_workdir_to_tree(&diff, g_repo, tree, &opts));
git_tree_free(tree); git_tree_free(tree);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment