diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-02-03 16:53:01 -0800 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-02 15:49:28 -0800 |
commit | 3a4375901a92efdc641c714ec9fd07b53f2f781e (patch) | |
tree | a0aed2d5e7ee9a6c2af317ae44e1f8bdce0a1446 /tests-clar/diff/diff_helpers.c | |
parent | 65b09b1deddec64fa5639e9fea10c048d31901fa (diff) | |
download | libgit2-3a4375901a92efdc641c714ec9fd07b53f2f781e.tar.gz |
Clean up diff implementation for review
This fixes several bugs, updates tests and docs, eliminates the
FILE* assumption in favor of printing callbacks for the diff patch
formatter helpers, and adds a "diff" example function that can
perform a diff from the command line.
Diffstat (limited to 'tests-clar/diff/diff_helpers.c')
-rw-r--r-- | tests-clar/diff/diff_helpers.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c index b2dbe9ee..3fcf45c1 100644 --- a/tests-clar/diff/diff_helpers.c +++ b/tests-clar/diff/diff_helpers.c @@ -20,3 +20,65 @@ git_tree *resolve_commit_oid_to_tree( git_object_free(obj); return tree; } + +int diff_file_fn( + void *cb_data, + git_diff_delta *delta, + float progress) +{ + diff_expects *e = cb_data; + (void)progress; + e->files++; + if (delta->old_attr == 0) + e->file_adds++; + else if (delta->new_attr == 0) + e->file_dels++; + else + e->file_mods++; + return 0; +} + +int diff_hunk_fn( + void *cb_data, + git_diff_delta *delta, + git_diff_range *range, + const char *header, + size_t header_len) +{ + diff_expects *e = cb_data; + (void)delta; + (void)header; + (void)header_len; + e->hunks++; + e->hunk_old_lines += range->old_lines; + e->hunk_new_lines += range->new_lines; + return 0; +} + +int diff_line_fn( + void *cb_data, + git_diff_delta *delta, + char line_origin, + const char *content, + size_t content_len) +{ + diff_expects *e = cb_data; + (void)delta; + (void)content; + (void)content_len; + e->lines++; + switch (line_origin) { + case GIT_DIFF_LINE_CONTEXT: + e->line_ctxt++; + break; + case GIT_DIFF_LINE_ADDITION: + e->line_adds++; + break; + case GIT_DIFF_LINE_DELETION: + e->line_dels++; + break; + default: + break; + } + return 0; +} |