chiark / gitweb /
Fix up .orig detection to be less trustful of (ambiguous) filenames.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 8 Oct 2016 12:19:54 +0000 (13:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 8 Oct 2016 15:02:44 +0000 (16:02 +0100)
We cannot simply match the filenaem because `foo_1.0.orig.tar.gz'
might be the `.orig.tar.gz' of foo version 1.0, or the `.tar.gz' of
foo version 1.0.orig.

We need either to consider the whole .dsc (this works since the
formats with no `.orig' or `.debian' or whatever are precisely ones
where there is only one file anyway), or know the version number.

Replace is_orig_file with two functions, one for each situation.

While we're here, do not barf if we find uncompressed tarballs.  (We
don't expect to find any but it would be nice if they worked...)

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

index e0d986c846a9847b36d11eaf378d05ccf615eedc..9082aad752f3c5611dfc3188821f2335d89eb479 100644 (file)
@@ -55,6 +55,7 @@ dgit (1.5~~) unstable; urgency=medium
     --quilt modes.
   * Fix two calls to chdir without proper error checking.
   * Fix a couple of bugs in error reporting.
+  * Fix up .orig detection to be less trustful of (ambiguous) filenames.
 
   Test suite:
   * When sbuild fails, do not crash due to sed not finding the log
diff --git a/dgit b/dgit
index 39231bbea6b0404b991d10e7594f27fc82210adc..c79deb48e4c5e686abaa87160db798081d3a7863 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -1429,12 +1429,20 @@ sub dsc_files () {
     map { $_->{Filename} } dsc_files_info();
 }
 
-sub is_orig_file ($;$) {
-    local ($_) = $_[0];
-    my $base = $_[1];
-    m/\.orig(?:-\w+)?\.tar\.\w+$/ or return 0;
-    defined $base or return 1;
-    return $` eq $base;
+sub is_orig_file_in_dsc ($$) {
+    my ($f, $dsc_files_info) = @_;
+    return 0 if @$dsc_files_info <= 1;
+    # One file means no origs, and the filename doesn't have a "what
+    # part of dsc" component.  (Consider versions ending `.orig'.)
+    return 0 unless $f =~ m/\.orig(?:-\w+)?\.tar(?:\.\w+)?$/;
+    return 1;
+}
+
+sub is_orig_file_of_vsn ($$) {
+    my ($f, $upstreamvsn) = @_;
+    my $base = srcfn $upstreamvsn, '';
+    return 0 unless $f =~ m/^\Q$base\E\.orig(?:-\w+)?\.tar(?:\.\w+)?$/;
+    return 1;
 }
 
 sub make_commit ($) {
@@ -1523,7 +1531,8 @@ sub generate_commits_from_dsc () {
     prep_ud();
     changedir $ud;
 
-    foreach my $fi (dsc_files_info()) {
+    my @dfi = dsc_files_info();
+    foreach my $fi (@dfi) {
        my $f = $fi->{Filename};
        die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
 
@@ -1534,7 +1543,7 @@ sub generate_commits_from_dsc () {
        complete_file_from_dsc('.', $fi)
            or next;
 
-       if (is_orig_file($f)) {
+       if (is_orig_file_in_dsc($f, \@dfi)) {
            link $f, "../../../../$f"
                or $!==&EEXIST
                or die "$f $!";
@@ -1643,9 +1652,10 @@ sub complete_file_from_dsc ($$) {
 }
 
 sub ensure_we_have_orig () {
-    foreach my $fi (dsc_files_info()) {
+    my @dfi = dsc_files_info();
+    foreach my $fi (@dfi) {
        my $f = $fi->{Filename};
-       next unless is_orig_file($f);
+       next unless is_orig_file_in_dsc($f, \@dfi);
        complete_file_from_dsc('..', $fi)
            or next;
     }
@@ -3754,7 +3764,7 @@ sub quilt_fixup_linkorigs ($$) {
            local ($debuglevel) = $debuglevel-1;
            printdebug "QF linkorigs $b, $f ?\n";
        }
-       next unless is_orig_file $b, srcfn $upstreamversion,'';
+       next unless is_orig_file_of_vsn $b, $upstreamversion;
        printdebug "QF linkorigs $b, $f Y\n";
        link_ltarget $f, $b or die "$b $!";
         $fn->($b);