diff options
author | Edward Thomson <ethomson@microsoft.com> | 2013-03-11 11:18:00 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2013-03-11 12:47:01 -0500 |
commit | aa408cbfc4940e05cb7843383264623e45737bb9 (patch) | |
tree | 02210552d4b2edd791a769b9854755bc000de2e6 /src | |
parent | d768f9add943e0ca220c81d7ffa29fc3215cd119 (diff) | |
download | libgit2-aa408cbfc4940e05cb7843383264623e45737bb9.tar.gz |
handle small files in similarity metrics
Diffstat (limited to 'src')
-rw-r--r-- | src/diff_tform.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/diff_tform.c b/src/diff_tform.c index 958d2bfec..e9969d9a8 100644 --- a/src/diff_tform.c +++ b/src/diff_tform.c @@ -174,16 +174,34 @@ static int find_similar__hashsig_for_file( void **out, const git_diff_file *f, const char *path, void *p) { git_hashsig_option_t opt = (git_hashsig_option_t)p; + int error = 0; + GIT_UNUSED(f); - return git_hashsig_create_fromfile((git_hashsig **)out, path, opt); + error = git_hashsig_create_fromfile((git_hashsig **)out, path, opt); + + if (error == GIT_EBUFS) { + error = 0; + giterr_clear(); + } + + return error; } static int find_similar__hashsig_for_buf( void **out, const git_diff_file *f, const char *buf, size_t len, void *p) { git_hashsig_option_t opt = (git_hashsig_option_t)p; + int error = 0; + GIT_UNUSED(f); - return git_hashsig_create((git_hashsig **)out, buf, len, opt); + error = git_hashsig_create((git_hashsig **)out, buf, len, opt); + + if (error == GIT_EBUFS) { + error = 0; + giterr_clear(); + } + + return error; } static void find_similar__hashsig_free(void *sig, void *payload) @@ -414,6 +432,10 @@ static int similarity_measure( return -1; if (!cache[b_idx] && similarity_calc(diff, opts, b_idx, cache) < 0) return -1; + + /* some metrics may not wish to process this file (too big / too small) */ + if (!cache[a_idx] || !cache[b_idx]) + return 0; /* compare signatures */ if (opts->metric->similarity( |