Commit 001d76e1 by Patrick Steinhardt

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.
parent ba9725a2
...@@ -460,7 +460,7 @@ out: ...@@ -460,7 +460,7 @@ out:
return error; return error;
} }
static int line_cb( static int patchid_line_cb(
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_hunk *hunk, const git_diff_hunk *hunk,
const git_diff_line *line, const git_diff_line *line,
...@@ -482,6 +482,14 @@ static int line_cb( ...@@ -482,6 +482,14 @@ static int line_cb(
break; break;
case GIT_DIFF_LINE_CONTEXT: case GIT_DIFF_LINE_CONTEXT:
break; 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: default:
git_error_set(GIT_ERROR_PATCH, "invalid line origin for patch"); git_error_set(GIT_ERROR_PATCH, "invalid line origin for patch");
return -1; return -1;
...@@ -518,7 +526,7 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt ...@@ -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) if ((error = git_hash_ctx_init(&args.ctx)) < 0)
goto out; 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; goto out;
if ((error = (flush_hunk(&args.result, &args.ctx))) < 0) if ((error = (flush_hunk(&args.result, &args.ctx))) < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment