diff options
author | Russell Belfer <rb@github.com> | 2012-09-24 20:52:34 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-09-25 16:35:05 -0700 |
commit | 5f69a31f7d706aa5788ad9937391577a66e3c77d (patch) | |
tree | 8201821372d02499f092b774a8fd521478564a7e /include/git2/diff.h | |
parent | 9a12a6256efa7da4b4245d0f2b7df6f3b84edabd (diff) | |
download | libgit2-5f69a31f7d706aa5788ad9937391577a66e3c77d.tar.gz |
Initial implementation of new diff patch API
Replacing the `git_iterator` object, this creates a simple API
for accessing the "patch" for any file pair in a diff list and
then gives indexed access to the hunks in the patch and the lines
in the hunk. This is the initial implementation of this revised
API - it is still broken, but at least builds cleanly.
Diffstat (limited to 'include/git2/diff.h')
-rw-r--r-- | include/git2/diff.h | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/include/git2/diff.h b/include/git2/diff.h index 2a5cdacc0..d216c1303 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -98,6 +98,9 @@ enum { GIT_DIFF_FILE_FREE_PATH = (1 << 1), GIT_DIFF_FILE_BINARY = (1 << 2), GIT_DIFF_FILE_NOT_BINARY = (1 << 3), + GIT_DIFF_FILE_FREE_DATA = (1 << 4), + GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), + GIT_DIFF_FILE_NO_DATA = (1 << 6), }; /** @@ -425,7 +428,7 @@ GIT_EXTERN(int) git_diff_print_patch( * @param diff A git_diff_list generated by one of the above functions * @return Count of number of deltas in the list */ -GIT_EXTERN(size_t) git_diff_entrycount(git_diff_list *diff); +GIT_EXTERN(size_t) git_diff_num_deltas(git_diff_list *diff); /** * Query how many diff deltas are there in a diff list filtered by type. @@ -438,7 +441,7 @@ GIT_EXTERN(size_t) git_diff_entrycount(git_diff_list *diff); * @param type A git_delta_t value to filter the count * @return Count of number of deltas matching delta_t type */ -GIT_EXTERN(size_t) git_diff_entrycount_of_type( +GIT_EXTERN(size_t) git_diff_num_deltas_of_type( git_diff_list *diff, git_delta_t type); @@ -469,7 +472,7 @@ GIT_EXTERN(size_t) git_diff_entrycount_of_type( */ GIT_EXTERN(int) git_diff_get_patch( git_diff_patch **patch, - const git_diff_delta **delta, + git_diff_delta **delta, git_diff_list *diff, size_t idx); @@ -482,43 +485,76 @@ GIT_EXTERN(void) git_diff_patch_free( /** * Get the delta associated with a patch */ -GIT_EXTERN(void) git_diff_patch_get_delta( - const git_diff_delta **delta, +GIT_EXTERN(const git_diff_delta *) git_diff_patch_delta( git_diff_patch *patch); /** * Get the number of hunks in a patch */ -GIT_EXTERN(size_t) git_diff_patch_hunks( +GIT_EXTERN(size_t) git_diff_patch_num_hunks( git_diff_patch *patch); /** * Get the information about a hunk in a patch + * + * Given a patch and a hunk index into the patch, this returns detailed + * information about that hunk. Any of the output pointers can be passed + * as NULL if you don't care about that particular piece of information. + * + * @param range Output pointer to git_diff_range of hunk + * @param header Output pointer to header string for hunk. Unlike the + * content pointer for each line, this will be NUL-terminated + * @param header_len Output value of characters in header string + * @param lines_in_hunk Output count of total lines in this hunk + * @param patch Input pointer to patch object + * @param hunk_idx Input index of hunk to get information about + * @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error */ GIT_EXTERN(int) git_diff_patch_get_hunk( - const git_diff_range **range, + git_diff_range **range, const char **header, size_t *header_len, size_t *lines_in_hunk, git_diff_patch *patch, - size_t hunk); + size_t hunk_idx); /** - * Get the number of lines in a hunk + * Get the number of lines in a hunk. + * + * @param patch The git_diff_patch object + * @param hunk_idx Index of the hunk + * @return Number of lines in hunk or -1 if invalid hunk index */ -GIT_EXTERN(size_t) git_diff_patch_lines_in_hunk( +GIT_EXTERN(int) git_diff_patch_num_lines_in_hunk( git_diff_patch *patch, - size_t hunk); + size_t hunk_idx); /** - * Get a line in a hunk of a patch + * Get data about a line in a hunk of a patch. + * + * Given a patch, a hunk index, and a line index in the hunk, this + * will return a lot of details about that line. If you pass a hunk + * index larger than the number of hunks or a line index larger than + * the number of lines in the hunk, this will return -1. + * + * @param line_origin A GIT_DIFF_LINE constant from above + * @param content Pointer to content of diff line, not NUL-terminated + * @param content_len Number of characters in content + * @param old_lineno Line number in old file or -1 if line is added + * @param new_lineno Line number in new file or -1 if line is deleted + * @param patch The patch to look in + * @param hunk_idx The index of the hunk + * @param line_of_index The index of the line in the hunk + * @return 0 on success, <0 on failure */ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk( char *line_origin, const char **content, size_t *content_len, + int *old_lineno, + int *new_lineno, git_diff_patch *patch, - size_t hunk, + size_t hunk_idx, size_t line_of_hunk); /**@}*/ |