From 82a62015a7b55a56f779b9ddfb98a3b0552d2bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 19 Aug 2020 00:08:54 +0200 Subject: patch-id: ignore newline at end of file in diff_flush_patch_id() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whitespace is ignored when calculating patch IDs. This is done by removing all whitespace from diff lines before hashing them, including a newline at the end of a file. If that newline is missing, however, diff reports that fact in a separate line containing "\ No newline at end of file\n", and this marker is hashed like a context line. This goes against our goal of making patch IDs independent of whitespace. Use the same heuristic that 2485eab55cc (git-patch-id: do not trip over "no newline" markers, 2011-02-17) added to git patch-id instead and skip diff lines that start with a backslash and a space and are longer than twelve characters. Reported-by: Tilman Vogel Initial-test-by: Tilman Vogel Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- diff.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'diff.c') diff --git a/diff.c b/diff.c index d24aaa3047..c10c28659e 100644 --- a/diff.c +++ b/diff.c @@ -6044,6 +6044,8 @@ static void patch_id_consume(void *priv, char *line, unsigned long len) struct patch_id_t *data = priv; int new_len; + if (len > 12 && starts_with(line, "\\ ")) + return; new_len = remove_space(line, len); the_hash_algo->update_fn(data->ctx, line, new_len); -- cgit v1.2.3