diff options
| author | Russell Belfer <rb@github.com> | 2013-05-15 14:58:26 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-05-15 14:58:26 -0700 |
| commit | 09fae31d45c3b9112cb7ce7d5c7d1d63840e407d (patch) | |
| tree | 386f91b3461258dac378f8c9e31ab653ca6a0339 /src/diff_tform.c | |
| parent | dcb0f7c061554de06db5879361b22eab3517a4ee (diff) | |
| download | libgit2-09fae31d45c3b9112cb7ce7d5c7d1d63840e407d.tar.gz | |
Improve robustness of diff rename detection
Under some strange circumstances, diffs can end up listing files
that we can't actually open successfully. Instead of aborting
the git_diff_find_similar, this makes it so that those files just
won't be considered as valid rename/copy targets instead.
Diffstat (limited to 'src/diff_tform.c')
| -rw-r--r-- | src/diff_tform.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/diff_tform.c b/src/diff_tform.c index 201a0e896..de2d5f616 100644 --- a/src/diff_tform.c +++ b/src/diff_tform.c @@ -386,8 +386,12 @@ static int similarity_calc( /* TODO: apply wd-to-odb filters to file data if necessary */ - if (!(error = git_buf_joinpath( - &path, git_repository_workdir(diff->repo), file->path))) + if ((error = git_buf_joinpath( + &path, git_repository_workdir(diff->repo), file->path)) < 0) + return error; + + /* if path is not a regular file, just skip this item */ + if (git_path_isfile(path.ptr)) error = opts->metric->file_signature( &cache[file_idx], file, path.ptr, opts->metric->payload); @@ -398,8 +402,11 @@ static int similarity_calc( /* TODO: add max size threshold a la diff? */ - if ((error = git_blob_lookup(&blob, diff->repo, &file->oid)) < 0) - return error; + if (git_blob_lookup(&blob, diff->repo, &file->oid) < 0) { + /* if lookup fails, just skip this item in similarity calc */ + giterr_clear(); + return 0; + } blobsize = git_blob_rawsize(blob); if (!git__is_sizet(blobsize)) /* ? what to do ? */ @@ -437,7 +444,7 @@ 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; |
