[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.4-168-g984040e



The following commit has been merged in the master branch:
commit 984040e2db339637a0048b785165f7f88d0fe6fb
Author: Niels Thykier <niels@thykier.net>
Date:   Tue Feb 14 22:10:42 2012 +0100

    source-copyright: Use line numbers instead of paragraph numbers
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/checks/source-copyright b/checks/source-copyright
index 450d260..2e589ce 100644
--- a/checks/source-copyright
+++ b/checks/source-copyright
@@ -69,6 +69,7 @@ $_ = slurp_entire_file($copyright_filename);
 study $_;
 
 my @dep5;
+my @lines;
 
 if (m{
     (^ | \n)
@@ -129,12 +130,11 @@ if (m{
                 # We are reasonably certain that we're dealing with an up-to-date
                 # DEP-5 format. Let's try to do more strict checks.
                 eval {
-                    @dep5 = read_dpkg_control($copyright_filename);
+                    @dep5 = read_dpkg_control($copyright_filename, 0, \@lines);
                 };
                 if ($@) {
                     chomp $@;
-                    $@ =~ s/^internal error: //;
-                    $@ =~ s/^syntax error in //;
+                    $@ =~ s/^syntax error at //;
                     tag 'syntax-error-in-dep5-copyright', $@;
                 }
             }
@@ -152,17 +152,17 @@ if (@dep5) {
     for my $field (keys %{$first_para}) {
         my $renamed_to = $dep5_renamed_fields{$field};
         if (defined $renamed_to) {
-            tag 'obsolete-field-in-dep5-copyright', $field, $renamed_to
+            tag 'obsolete-field-in-dep5-copyright', $field, $renamed_to, "(paragraph at line $lines[0])";
         }
     }
     if (not defined $first_para->{'format'} and not defined $first_para->{'format-specification'}) {
-        tag 'missing-field-in-dep5-copyright', 'paragraph', '1', 'format';
+        tag 'missing-field-in-dep5-copyright', 'format', "(paragraph at line $lines[0])";
     }
     for my $license (split_licenses($first_para->{'license'})) {
         $required_standalone_licenses{$license} = 1;
     }
     my $commas_in_files = 0;
-    my $i = 1;
+    my $i = 0;
     for my $para (@dep5) {
         $i++;
         my $license = $para->{'license'};
@@ -170,7 +170,7 @@ if (@dep5) {
         if (defined $license and not defined $files) {
             # Standalone license paragraph
             if (not $license =~ m/\n/) {
-                tag 'missing-license-text-in-dep5-copyright', 'paragraph', $i, "\L$license";
+                tag 'missing-license-text-in-dep5-copyright', lc $license, "(paragrah at line $lines[$i])";
             }
             ($license, undef) = split /\n/, $license, 2;
             for (split_licenses($license)) {
@@ -179,35 +179,35 @@ if (@dep5) {
         }
         elsif (defined $files) {
             # Files paragraph
-            $commas_in_files = 1 if $files =~ /,/;
+            $commas_in_files = $i if not $commas_in_files and $files =~ /,/;
             if (defined $license) {
                 for (split_licenses($license)) {
                     $required_standalone_licenses{$_} = $i;
                 }
             }
             else {
-                tag 'missing-field-in-dep5-copyright', 'paragraph', $i, 'license';
+                tag 'missing-field-in-dep5-copyright', "license (paragraph at line $lines[$i])";
             }
             if (not defined $para->{'copyright'}) {
-                tag 'missing-field-in-dep5-copyright', 'paragraph', $i, 'copyright';
+                tag 'missing-field-in-dep5-copyright', "copyright (paragraph at line $lines[$i])";
             }
         }
         else {
-            tag 'unknown-paragraph-in-dep5-copyright', 'paragraph', $i;
+            tag 'unknown-paragraph-in-dep5-copyright', 'paragraph at line', $lines[$i];
         }
     }
     if ($commas_in_files) {
-        tag 'comma-separated-files-in-dep5-copyright'
+        tag 'comma-separated-files-in-dep5-copyright', 'paragraph at line', $lines[$i]
             unless grep(/,/, $info->sorted_index);
     }
     while ((my $license, $i) = each %required_standalone_licenses) {
         if (not defined $standalone_licenses{$license}) {
-            tag 'missing-license-paragraph-in-dep5-copyright', 'paragraph', $i, $license;
+            tag 'missing-license-paragraph-in-dep5-copyright', $license, "(paragraph at line $lines[$i])";
         }
     }
     while ((my $license, $i) = each %standalone_licenses) {
         if (not defined $required_standalone_licenses{$license}) {
-            tag 'unused-license-paragraph-in-dep5-copyright', 'paragraph', $i, $license;
+            tag 'unused-license-paragraph-in-dep5-copyright', $license, "(paragraph at line $lines[$i])";
         }
     }
 }
diff --git a/checks/source-copyright.desc b/checks/source-copyright.desc
index 8f629be..bd800a5 100644
--- a/checks/source-copyright.desc
+++ b/checks/source-copyright.desc
@@ -94,6 +94,8 @@ Certainty: possible
 Ref: http://dep.debian.net/deps/dep5/
 Info: A list of files in the machine-readable copyright format appears to be
  separated by commas.  The file list should be whitespace separated instead.
+ .
+ Please note this tag is only emitted once per checked copyright file.
 
 Tag: missing-field-in-dep5-copyright
 Severity: normal
diff --git a/debian/changelog b/debian/changelog
index 9c4dd1d..58d9c48 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -131,6 +131,8 @@ lintian (2.5.5) UNRELEASED; urgency=low
   * checks/source-copyright:
     + [JW] Allow a trailing slash in the DEP-5 1.0 URL.
       (Closes: #649813)
+    + [NT] Use line numbers rather than "0-indexed" paragraph numbers
+      in the emitted tags.  Thanks to Jari Aalto for the suggestion.
   * checks/symlinks:
     + [NT] Ignore langpack symlinks if they appear to be consistent.
       Thanks to Evan Broder for the report.  (Closes: #650793)
diff --git a/lib/Util.pm b/lib/Util.pm
index 18a768e..543db18 100644
--- a/lib/Util.pm
+++ b/lib/Util.pm
@@ -62,6 +62,7 @@ use Digest::MD5;
 # arguments:
 #    $filehandle
 #    $debconf_flag (true if the file is a debconf template file)
+#    $lines (will be updated to contain line number of each paragraph)
 # output:
 #    list of hashes
 #    (a hash contains one sections,
@@ -79,7 +80,7 @@ sub parse_dpkg_control {
 # large dpkg-control based files without having the entire file
 # in memory.
 sub _parse_dpkg_control_iterative {
-    my ($code, $CONTROL, $debconf_flag) = @_;
+    my ($code, $CONTROL, $debconf_flag, $lines) = @_;
 
     my $section = {};
     my $open_section = 0;
@@ -116,6 +117,7 @@ sub _parse_dpkg_control_iterative {
         }
         # new empty field?
         elsif (m/^([^: \t]+):\s*$/o) {
+            push @$lines, $. if defined $lines and not $open_section;
             $open_section = 1;
 
             my ($tag) = (lc $1);
@@ -125,6 +127,7 @@ sub _parse_dpkg_control_iterative {
         }
         # new field?
         elsif (m/^([^: \t]+):\s*(.*)$/o) {
+            push @$lines, $. if defined $lines and not $open_section;
             $open_section = 1;
 
             # Policy: Horizontal whitespace (spaces and tabs) may occur
@@ -165,7 +168,7 @@ sub _parse_dpkg_control_iterative {
 }
 
 sub read_dpkg_control {
-    my ($file, $debconf_flag) = @_;
+    my ($file, $debconf_flag, $lines) = @_;
 
     if (not _ensure_file_is_sane($file)) {
         return;
@@ -173,7 +176,7 @@ sub read_dpkg_control {
 
     open(my $CONTROL, '<', $file)
         or fail("cannot open control file $file for reading: $!");
-    my @data = parse_dpkg_control($CONTROL, $debconf_flag);
+    my @data = parse_dpkg_control($CONTROL, $debconf_flag, $lines);
     close($CONTROL)
         or fail("pipe for control file $file exited with status: $?");
     return @data;
diff --git a/t/tests/source-copyright-dep5-general/tags b/t/tests/source-copyright-dep5-general/tags
index a85d85d..3f1e1a7 100644
--- a/t/tests/source-copyright-dep5-general/tags
+++ b/t/tests/source-copyright-dep5-general/tags
@@ -1,8 +1,8 @@
-I: source-copyright-dep5-general source: unused-license-paragraph-in-dep5-copyright paragraph 9 expat
-W: source-copyright-dep5-general source: comma-separated-files-in-dep5-copyright
-W: source-copyright-dep5-general source: missing-field-in-dep5-copyright paragraph 4 license
-W: source-copyright-dep5-general source: missing-field-in-dep5-copyright paragraph 5 copyright
-W: source-copyright-dep5-general source: missing-license-paragraph-in-dep5-copyright paragraph 6 mit
-W: source-copyright-dep5-general source: missing-license-text-in-dep5-copyright paragraph 8 gpl-3
-W: source-copyright-dep5-general source: obsolete-field-in-dep5-copyright upstream-maintainer upstream-contact
-W: source-copyright-dep5-general source: unknown-paragraph-in-dep5-copyright paragraph 2
+I: source-copyright-dep5-general source: unused-license-paragraph-in-dep5-copyright expat (paragraph at line 40)
+W: source-copyright-dep5-general source: comma-separated-files-in-dep5-copyright paragraph at line 40
+W: source-copyright-dep5-general source: missing-field-in-dep5-copyright copyright (paragraph at line 15)
+W: source-copyright-dep5-general source: missing-field-in-dep5-copyright license (paragraph at line 12)
+W: source-copyright-dep5-general source: missing-license-paragraph-in-dep5-copyright mit (paragraph at line 18)
+W: source-copyright-dep5-general source: missing-license-text-in-dep5-copyright gpl-3 (paragrah at line 38)
+W: source-copyright-dep5-general source: obsolete-field-in-dep5-copyright upstream-maintainer upstream-contact (paragraph at line 1)
+W: source-copyright-dep5-general source: unknown-paragraph-in-dep5-copyright paragraph at line 6
diff --git a/t/tests/source-copyright-dep5-syntax-error/tags b/t/tests/source-copyright-dep5-syntax-error/tags
index cbcc70f..7488b2f 100644
--- a/t/tests/source-copyright-dep5-syntax-error/tags
+++ b/t/tests/source-copyright-dep5-syntax-error/tags
@@ -1 +1 @@
-W: source-copyright-dep5-syntax-error source: syntax-error-in-dep5-copyright syntax error at line 13: Continuation line outside a paragraph.
+W: source-copyright-dep5-syntax-error source: syntax-error-in-dep5-copyright line 13: Continuation line outside a paragraph.

-- 
Debian package checker


Reply to: