diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-07-11 11:34:40 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-07-11 11:34:40 +0200 |
commit | 001d76e1fe783448cd6d241c59cf69b1e0dd1aaa (patch) | |
tree | dc0cf8bb8cc8881c76091b63e8055e4ffb878b4d /src | |
parent | ba9725a28f351e52c8054e543298f78d4d5f2cf0 (diff) | |
download | libgit2-001d76e1fe783448cd6d241c59cf69b1e0dd1aaa.tar.gz |
diff: ignore EOFNL for computing patch IDs
The patch ID is supposed to be mostly context-insignificant and
thus only includes added or deleted lines. As such, we shouldn't honor
end-of-file-without-newline markers in diffs.
Ignore such lines to fix how we compute the patch ID for such diffs.
Diffstat (limited to 'src')
-rw-r--r-- | src/diff.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/diff.c b/src/diff.c index 6c2592137..3c6a0f242 100644 --- a/src/diff.c +++ b/src/diff.c @@ -460,7 +460,7 @@ out: return error; } -static int line_cb( +static int patchid_line_cb( const git_diff_delta *delta, const git_diff_hunk *hunk, const git_diff_line *line, @@ -482,6 +482,14 @@ static int line_cb( break; case GIT_DIFF_LINE_CONTEXT: break; + case GIT_DIFF_LINE_CONTEXT_EOFNL: + case GIT_DIFF_LINE_ADD_EOFNL: + case GIT_DIFF_LINE_DEL_EOFNL: + /* + * Ignore EOF without newlines for patch IDs as whitespace is + * not supposed to be significant. + */ + return 0; default: git_error_set(GIT_ERROR_PATCH, "invalid line origin for patch"); return -1; @@ -518,7 +526,7 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt if ((error = git_hash_ctx_init(&args.ctx)) < 0) goto out; - if ((error = git_diff_foreach(diff, file_cb, NULL, NULL, line_cb, &args)) < 0) + if ((error = git_diff_foreach(diff, file_cb, NULL, NULL, patchid_line_cb, &args)) < 0) goto out; if ((error = (flush_hunk(&args.result, &args.ctx))) < 0) |