chiark / gitweb /
dgit: Before committing to push, check that .dsc and .changes correspond.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 9 Oct 2016 12:56:57 +0000 (13:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 Oct 2016 00:01:11 +0000 (01:01 +0100)
Closes:#800060.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
debian/changelog
dgit

index f59e395e7b83aac6ac66f950e4d529c0db145070..a751449a9dad81511a93dba39dade4ec8ee1895c 100644 (file)
@@ -42,6 +42,8 @@ dgit (1.5~~) unstable; urgency=medium
     from dgit about what it was doing.
   * Make --quilt=gbp the default for dgit gbp-build.
   * New tag format (for dgit view) archive/debian/VERSION.
+  * Before committing to push, check that .dsc and .changes correspond.
+    Closes:#800060.
 
   Infrastructure:
   * Better error handling in dgit-repos-policy-debian.
diff --git a/dgit b/dgit
index ae1e6b5724a4ee5cbdaa16987345dc5156c64927..fa926dd0096d4db23a4a5af959030f6f4ccef7f2 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -1448,6 +1448,65 @@ sub dsc_files () {
     map { $_->{Filename} } dsc_files_info();
 }
 
+sub files_compare_inputs (@) {
+    my $inputs = \@_;
+    my %record;
+    my %fchecked;
+
+    my $showinputs = sub {
+       return join "; ", map { $_->get_option('name') } @$inputs;
+    };
+
+    foreach my $in (@$inputs) {
+       my $expected_files;
+       my $in_name = $in->get_option('name');
+
+       printdebug "files_compare_inputs $in_name\n";
+
+       foreach my $csumi (@files_csum_info_fields) {
+           my ($fname) = @$csumi;
+           printdebug "files_compare_inputs $in_name $fname\n";
+
+           my $field = $in->{$fname};
+           next unless defined $field;
+
+           my @files;
+           foreach (split /\n/, $field) {
+               next unless m/\S/;
+
+               my ($info, $f) = m/^(\w+ \d+) (?:\S+ \S+ )?(\S+)$/ or
+                   fail "could not parse $in_name $fname line \`$_'";
+
+               printdebug "files_compare_inputs $in_name $fname $f\n";
+
+               push @files, $f;
+
+               my $re = \ $record{$f}{$fname};
+               if (defined $$re) {
+                   $fchecked{$f}{$in_name} = 1;
+                   $$re eq $info or
+                       fail "hash or size of $f varies in $fname fields".
+                       " (between: ".$showinputs->().")";
+               } else {
+                   $$re = $info;
+               }
+           }
+           @files = sort @files;
+           $expected_files //= \@files;
+           "@$expected_files" eq "@files" or
+               fail "file list in $in_name varies between hash fields!";
+       }
+       $expected_files or
+           fail "$in_name has no files list field(s)";
+    }
+    printdebug "files_compare_inputs ".Dumper(\%fchecked, \%record)
+       if $debuglevel>=2;
+
+    grep { keys %$_ == @$inputs-1 } values %fchecked
+       or fail "no file appears in all file lists".
+       " (looked in: ".$showinputs->().")";
+}
+
 sub is_orig_file_in_dsc ($$) {
     my ($f, $dsc_files_info) = @_;
     return 0 if @$dsc_files_info <= 1;
@@ -3166,6 +3225,10 @@ END
        $changesfile = "$buildproductsdir/$changesfile";
     }
 
+    # Check that changes and .dsc agree enough
+    $changesfile =~ m{[^/]*$};
+    files_compare_inputs($dsc, parsecontrol($changesfile,$&));
+
     # Checks complete, we're going to try and go ahead:
 
     responder_send_file('changes',$changesfile);