diff options
author | Vicent Martà <vicent@github.com> | 2012-11-02 10:00:28 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-11-02 10:00:28 -0700 |
commit | 1362a983165abb5e85e66c2b0474157ba697966a (patch) | |
tree | 2dcd99e991224a26eb860d36151405219ff202bd /include/git2/diff.h | |
parent | 473a7a1e70d05ec125309304d56f060c3e3ad40e (diff) | |
parent | db106d01f093b3e61170e3738d6651a2866cb76e (diff) | |
download | libgit2-1362a983165abb5e85e66c2b0474157ba697966a.tar.gz |
Merge pull request #1014 from arrbee/diff-rename-detection
Initial implementation of diff rename detection
Diffstat (limited to 'include/git2/diff.h')
-rw-r--r-- | include/git2/diff.h | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/include/git2/diff.h b/include/git2/diff.h index 4e80bed56..9b11f169b 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -33,7 +33,7 @@ GIT_BEGIN_DECL * Flags for diff options. A combination of these flags can be passed * in via the `flags` value in the `git_diff_options`. */ -enum { +typedef enum { /** Normal diff, the default */ GIT_DIFF_NORMAL = 0, /** Reverse the sides of the diff */ @@ -86,7 +86,7 @@ enum { * mode set to tree. Note: the tree SHA will not be available. */ GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1 << 16), -}; +} git_diff_option_t; /** * Structure describing options about how the diff should be executed. @@ -95,7 +95,7 @@ enum { * values. Similarly, passing NULL for the options structure will * give the defaults. The default values are marked below. * - * - flags: a combination of the GIT_DIFF_... values above + * - flags: a combination of the git_diff_option_t values above * - context_lines: number of lines of context to show around diffs * - interhunk_lines: min lines between diff hunks to merge them * - old_prefix: "directory" to prefix to old file names (default "a") @@ -124,7 +124,7 @@ typedef struct git_diff_list git_diff_list; * Most of the flags are just for internal consumption by libgit2, * but some of them may be interesting to external users. */ -enum { +typedef enum { GIT_DIFF_FILE_VALID_OID = (1 << 0), /** `oid` value is known correct */ GIT_DIFF_FILE_FREE_PATH = (1 << 1), /** `path` is allocated memory */ GIT_DIFF_FILE_BINARY = (1 << 2), /** should be considered binary data */ @@ -132,7 +132,7 @@ enum { GIT_DIFF_FILE_FREE_DATA = (1 << 4), /** internal file data is allocated */ GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), /** internal file data is mmap'ed */ GIT_DIFF_FILE_NO_DATA = (1 << 6), /** file data should not be loaded */ -}; +} git_diff_file_flag_t; /** * What type of change is described by a git_diff_delta? @@ -218,7 +218,7 @@ typedef int (*git_diff_hunk_fn)( * output callbacks to demarcate lines that are actually part of * the file or hunk headers. */ -enum { +typedef enum { /* These values will be sent to `git_diff_data_fn` along with the line */ GIT_DIFF_LINE_CONTEXT = ' ', GIT_DIFF_LINE_ADDITION = '+', @@ -233,7 +233,7 @@ enum { GIT_DIFF_LINE_FILE_HDR = 'F', GIT_DIFF_LINE_HUNK_HDR = 'H', GIT_DIFF_LINE_BINARY = 'B' -}; +} git_diff_line_t; /** * When iterating over a diff, callback that will be made per text diff @@ -259,6 +259,46 @@ typedef int (*git_diff_data_fn)( */ typedef struct git_diff_patch git_diff_patch; +/** + * Flags to control the behavior of diff rename/copy detection. + */ +typedef enum { + /** look for renames? (`--find-renames`) */ + GIT_DIFF_FIND_RENAMES = (1 << 0), + /** consider old size of modified for renames? (`--break-rewrites=N`) */ + GIT_DIFF_FIND_RENAMES_FROM_REWRITES = (1 << 1), + + /** look for copies? (a la `--find-copies`) */ + GIT_DIFF_FIND_COPIES = (1 << 2), + /** consider unmodified as copy sources? (`--find-copies-harder`) */ + GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED = (1 << 3), + + /** split large rewrites into delete/add pairs (`--break-rewrites=/M`) */ + GIT_DIFF_FIND_AND_BREAK_REWRITES = (1 << 4), +} git_diff_find_t; + +/** + * Control behavior of rename and copy detection + */ +typedef struct { + /** Combination of git_diff_find_t values (default FIND_RENAMES) */ + unsigned int flags; + + /** Similarity to consider a file renamed (default 50) */ + unsigned int rename_threshold; + /** Similarity of modified to be eligible rename source (default 50) */ + unsigned int rename_from_rewrite_threshold; + /** Similarity to consider a file a copy (default 50) */ + unsigned int copy_threshold; + /** Similarity to split modify into delete/add pair (default 60) */ + unsigned int break_rewrite_threshold; + + /** Maximum similarity sources to examine (a la diff's `-l` option or + * the `diff.renameLimit` config) (default 200) + */ + unsigned int target_limit; +} git_diff_find_options; + /** @name Diff List Generator Functions * @@ -374,6 +414,22 @@ GIT_EXTERN(int) git_diff_merge( git_diff_list *onto, const git_diff_list *from); +/** + * Transform a diff list marking file renames, copies, etc. + * + * This modifies a diff list in place, replacing old entries that look + * like renames or copies with new entries reflecting those changes. + * This also will, if requested, break modified files into add/remove + * pairs if the amount of change is above a threshold. + * + * @param diff Diff list to run detection algorithms on + * @param options Control how detection should be run, NULL for defaults + * @return 0 on success, -1 on failure + */ +GIT_EXTERN(int) git_diff_find_similar( + git_diff_list *diff, + git_diff_find_options *options); + /**@}*/ |