summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2020-08-19 00:08:54 +0200
committerJunio C Hamano <gitster@pobox.com>2020-08-18 16:14:01 -0700
commit82a62015a7b55a56f779b9ddfb98a3b0552d2bb4 (patch)
tree0000a420a30cea4448b2da8954ec3dce797dfcdf /diff.c
parent47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc (diff)
downloadgit-82a62015a7b55a56f779b9ddfb98a3b0552d2bb4.tar.gz
patch-id: ignore newline at end of file in diff_flush_patch_id()
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 <tilman.vogel@web.de> Initial-test-by: Tilman Vogel <tilman.vogel@web.de> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c2
1 files changed, 2 insertions, 0 deletions
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);