From 67fcbe7bc6767cbcf6991c0c0a6ca799349bd901 Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Date: Fri, 17 Oct 2014 15:21:35 +0200
Subject: [PATCH] add line number information to more diff-related complaints

Change-Id: I38ecc06bfc8d24f1df89812a8b86bd78970e095b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
---
 git-hooks/sanitize-commit | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/git-hooks/sanitize-commit b/git-hooks/sanitize-commit
index 2d29d7e..0546526 100755
--- a/git-hooks/sanitize-commit
+++ b/git-hooks/sanitize-commit
@@ -503,7 +503,8 @@ while (<DIFF>) {
             $no_copyright = 0;
         }
         if ($check_gen && /All changes made in this file will be lost|This file is automatically generated|DO NOT EDIT|DO NOT delete this file|[Gg]enerated by|uicgenerated|produced by gperf|made by GNU Bison/) {
-            complain("Adding generated file", "generated") if ($new_file && !defined($cfg{generated}));
+            complain("Adding generated file (inferred from line ".($lineno + 1).")", "generated")
+                if ($new_file && !defined($cfg{generated}));
             $ws_check = 0;
             $check_gen = 0;
         }
@@ -537,10 +538,16 @@ while (<DIFF>) {
         $in_plus = 1;
         if (!$crlf_fail && /\r\n$/) {
             $crlf_fail = 1;
-            complain("CRLF line endings", "crlf");
+            if ($lineno != 1) {
+                # A stray CRLF somewhere in the middle.
+                complain_ln("CRLF line endings", "crlf");
+            } else {
+                # Assume that the whole file is affected.
+                complain("CRLF line endings", "crlf");
+            }
         }
         if (!$conflict_fail && /^(?:[<>=]){7}( |$)/) {
-            complain("Unresolved merge conflict", "conflict");
+            complain_ln("Unresolved merge conflict", "conflict");
             $conflict_fail = 1;
         }
         if ($ws_check) {
-- 
GitLab