From ef4f1434841acb955ecf586b168e83f70d4e9e1c Mon Sep 17 00:00:00 2001
From: Rohan McGovern <rohan@mcgovern.id.au>
Date: Fri, 11 Jan 2013 08:42:08 +1000
Subject: [PATCH] sanitize-commit: combine $ln and $lineno variables

Use a single variable for the current line number of the commit message
and of the current file, in preparation for new checks which use this information.

Note that $lineno always counts from 1. Previously, $ln counted from 0 while
$lineno counted from 1.

Change-Id: I3a87d29df1378e304a27a7672630f0319dc863a2
Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
---
 git-hooks/sanitize-commit | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/git-hooks/sanitize-commit b/git-hooks/sanitize-commit
index 0cbb54b..7271c18 100755
--- a/git-hooks/sanitize-commit
+++ b/git-hooks/sanitize-commit
@@ -88,7 +88,7 @@ sub complain()
     }
 }
 
-my $ln = 0;
+my $lineno = 0;
 my $iswip = defined($cfg{wip});
 my $revok = defined($cfg{revby});
 my $badlog = defined($cfg{log});
@@ -108,7 +108,8 @@ while (<MSG>) {
         }
         next
     }
-    if ($ln == 0) {
+    $lineno++;
+    if ($lineno == 1) {
         $summary = $_;
         $revert1 = 1 if (/^Revert ".*"$/);
         if (!$iswip && $parents < 2 && /\bWIP\b|\*{3}|^(?:squash|fixup)! |^(.)\1*$/i) {
@@ -126,7 +127,7 @@ while (<MSG>) {
         } elsif (!/^[-\w]+:|^$/) {
             $nonrevert = 1;
         }
-        if ($ln == 1) {
+        if ($lineno == 2) {
             if (!$badlog && $_ ne "") {
                 &complain("2nd line of log message is not empty", "log");
             }
@@ -137,7 +138,6 @@ while (<MSG>) {
             }
         }
     }
-    $ln++;
 }
 close MSG;
 printerr;
@@ -159,7 +159,6 @@ my @deli = ();
 my $nonws;
 my $ws;
 my $mixws_check = 0;
-my $lineno = 0;
 my @ws_files = ();
 my %ws_lines = (); # hash of lists
 my $braces = 0;
@@ -168,6 +167,8 @@ my $close_key = qr/\s*#\s*endif|.*}/;
 my $kill_all_ws = qr/\s+((?:\"(?:\\.|[^\"])*\"|\S)+)/; # Collapse all whitespace not inside strings.
 my $kill_nl_ws = qr/((?:\"(?:\\.|[^\"])*\"|\S)+)\s+/; # Collapse all non-leading whitespace not inside strings.
 
+$lineno = 0;
+
 sub flushChunk()
 {
     my $loc_nonws = 0;
-- 
GitLab