chiark / gitweb /
changelog: start 9.10
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 0775a7c1f31a7337a2c57cde033d77b72af8a734..4804c9bd055f39880a28676ce5ec8bac62099cd2 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -46,6 +46,7 @@ use Digest::SHA;
 use Digest::MD5;
 use List::MoreUtils qw(pairwise);
 use Text::Glob qw(match_glob);
+use Text::CSV;
 use Fcntl qw(:DEFAULT :flock);
 use Carp;
 
@@ -101,6 +102,7 @@ our %forceopts = map { $_=>0 }
     qw(unrepresentable unsupported-source-format
        dsc-changes-mismatch changes-origs-exactly
        uploading-binaries uploading-source-only
+       reusing-version
        import-gitapply-absurd
        import-gitapply-no-absurd
        import-dsc-with-dgit-field);
@@ -867,6 +869,22 @@ sub access_basedistro__noalias () {
                return $kl->{$k};
            }
        }
+       foreach my $csvf (</usr/share/distro-info/*.csv>) {
+           my $csv_distro =
+               $csvf =~ m{/(\w+)\.csv$} ? $1 : do {
+                   printdebug "skipping $csvf\n";
+                   next;
+               };
+           my $csv = Text::CSV->new({ binary => 1, auto_diag => 2 }) or die;
+           my $fh = new IO::File $csvf, "<:encoding(utf8)"
+               or die "open $csvf: $!";
+           while (my $cols = $csv->getline($fh)) {
+               next unless $cols->[2] eq $isuite;
+               return $csv_distro;
+           }
+           die "$csvf $!" if $fh->error;
+           close $fh;
+       }
        return cfg("dgit.default.distro");
     }
 }
@@ -1192,6 +1210,7 @@ sub url_fetch ($;@) {
     };
 
     my $response_body = '';
+    $setopt->(CURLOPT_FOLLOWLOCATION,  1);
     $setopt->(CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS|CURLPROTO_HTTP);
     $setopt->(CURLOPT_URL,             $url);
     $setopt->(CURLOPT_NOSIGNAL,        1);
@@ -1736,7 +1755,7 @@ sub get_archive_dsc () {
     foreach my $vinfo (@vsns) {
        my ($vsn,$vsn_dscurl,$digester,$digest) = @$vinfo;
        $dscurl = $vsn_dscurl;
-       $dscdata = url_fetch($dscurl);
+       $dscdata = url_fetch($dscurl, Ok404 => 1 );
        if (!$dscdata) {
            $skew_warning_vsn = $vsn if !defined $skew_warning_vsn;
            next;
@@ -2015,7 +2034,7 @@ sub test_source_only_changes ($) {
     foreach my $l (split /\n/, getfield $changes, 'Files') {
         $l =~ m/\S+$/ or next;
         # \.tar\.[a-z0-9]+ covers orig.tar and the tarballs in native packages
-        unless ($& =~ m/(?:\.dsc|\.diff\.gz|\.tar\.[a-z0-9]+|_source\.buildinfo)$/) {
+        unless ($& =~ m/(?:\.dsc|\.diff\.gz|$tarball_f_ext_re|_source\.buildinfo)$/) {
             print f_ "purportedly source-only changes polluted by %s\n", $&;
             return 0;
         }
@@ -3848,6 +3867,16 @@ END
     printdone f_ "ready for work in %s", $dstdir;
 }
 
+sub vcs_git_url_of_ctrl ($) {
+    my ($ctrl) = @_;
+    my $vcsgiturl = $ctrl->{'Vcs-Git'};
+    if (length $vcsgiturl) {
+       $vcsgiturl =~ s/\s+-b\s+\S+//g;
+       $vcsgiturl =~ s/\s+\[[^][]*\]//g;
+    }
+    return $vcsgiturl;
+}
+
 sub clone ($) {
     # in multisuite, returns twice!
     # once in parent after first suite fetched,
@@ -3886,9 +3915,8 @@ sub clone ($) {
        progress __ "starting new git history";
     }
     fetch_from_archive() or no_such_package;
-    my $vcsgiturl = $dsc->{'Vcs-Git'};
+    my $vcsgiturl = vcs_git_url_of_ctrl $dsc;
     if (length $vcsgiturl) {
-       $vcsgiturl =~ s/\s+-b\s+\S+//g;
        runcmd @git, qw(remote add vcs-git), $vcsgiturl;
     }
     clone_finish($dstdir);
@@ -4575,6 +4603,20 @@ END
 
     confess unless !!$made_split_brain == do_split_brain();
 
+    my $tagname = debiantag_new $cversion, access_nomdistro();
+    if (!(forceing[qw(reusing-version)]) && git_get_ref "refs/tags/$tagname") {
+       supplementary_message '';
+       print STDERR f_ <<END, $cversion;
+
+Version %s has already been tagged (pushed?)
+If this was a failed (or incomplete or rejected) upload by you, just
+add a new changelog stanza for a new version number and try again.
+END
+       fail f_ <<END, $tagname;
+Tag %s already exists.
+END
+    }
+
     changedir $playground;
     progress f_ "checking that %s corresponds to HEAD", $dscfn;
     runcmd qw(dpkg-source -x --),
@@ -4964,7 +5006,8 @@ sub cmd_update_vcs_git () {
        get_archive_dsc();
        $ctrl = $dsc;
     }
-    my $url = getfield $ctrl, 'Vcs-Git';
+    my $url = vcs_git_url_of_ctrl $ctrl;
+    fail 'no Vcs-Git header in control file' unless length $url;
 
     my @cmd;
     my $orgurl = cfg 'remote.vcs-git.url', 'RETURN-UNDEF';
@@ -4972,12 +5015,12 @@ sub cmd_update_vcs_git () {
        print STDERR f_ "setting up vcs-git: %s\n", $url;
        @cmd = (@git, qw(remote add vcs-git), $url);
     } elsif ($orgurl eq $url) {
-       print STDERR f_ "vcs git already configured: %s\n", $url;
+       print STDERR f_ "vcs git unchanged: %s\n", $url;
     } else {
        print STDERR f_ "changing vcs-git url to: %s\n", $url;
        @cmd = (@git, qw(remote set-url vcs-git), $url);
     }
-    runcmd_ordryrun_local @cmd;
+    runcmd_ordryrun_local @cmd if @cmd;
     if ($dofetch) {
        print f_ "fetching (%s)\n", "@ARGV";
        runcmd_ordryrun_local @git, qw(fetch vcs-git), @ARGV;
@@ -6652,6 +6695,31 @@ sub build_prep ($) {
     }
 }
 
+sub maybe_warn_opt_confusion ($$$) {
+    my ($subcommand, $willrun, $optsref) = @_;
+    foreach (@$optsref) {
+       if (m/^(?: --dry-run  $
+                | --damp-run $
+                | --clean= | -w[gcnd]
+                | --(?:include|ignore)-dirty$
+                | --quilt= | --gbp$ | --dpm$ | --baredebian
+                | --split-view=
+                | --build-products-dir=
+                )/x) {
+           print STDERR f_ <<END, $&, $subcommand or die $!;
+warning: dgit option %s must be passed before %s on dgit command line
+END
+       } elsif (m/^(?: -C
+                     | --no-sign  $
+                     | -k
+                     )/x) {
+           print STDERR f_ <<END, $&, $subcommand, $willrun or die $!;
+warning: option %s should probably be passed to dgit before %s sub-command on the dgit command line, so that it is seen by dgit and not simply passed to %s
+END
+       }
+    }
+}
+
 sub changesopts_initial () {
     my @opts =@changesopts[1..$#changesopts];
 }
@@ -6825,6 +6893,7 @@ sub postbuild_mergechanges_vanilla ($) {
 
 sub cmd_build {
     build_prep_early();
+    maybe_warn_opt_confusion 'build', 'dpkg-buildpackage', \@ARGV;
     $buildproductsdir eq '..' or print STDERR +(f_ <<END, $us, $us);
 %s: warning: build-products-dir set, but not supported by dpkg-buildpackage
 %s: warning: build-products-dir will be ignored; files will go to ..
@@ -6852,6 +6921,7 @@ sub pre_gbp_build {
 
 sub cmd_gbp_build {
     build_prep_early();
+    maybe_warn_opt_confusion 'gbp-build', 'gbp buildpackage', \@ARGV;
 
     # gbp can make .origs out of thin air.  In my tests it does this
     # even for a 1.0 format package, with no origs present.  So I
@@ -7059,6 +7129,7 @@ sub binary_builder {
 
 sub cmd_sbuild {
     build_prep_early();
+    maybe_warn_opt_confusion 'sbuild', 'sbuild', \@ARGV;
     binary_builder(\@sbuild, (__ <<END), qw(-d), $isuite, @ARGV, $dscfn);
 perhaps you need to pass -A ?  (sbuild's default is to build only
 arch-specific binaries; dgit 1.4 used to override that.)
@@ -7068,6 +7139,7 @@ END
 sub pbuilder ($) {
     my ($pbuilder) = @_;
     build_prep_early();
+    maybe_warn_opt_confusion 'pbuilder', 'pbuilder', \@ARGV;
     # @ARGV is allowed to contain only things that should be passed to
     # pbuilder under debbuildopts; just massage those
     my $wantsrc = massage_dbp_args \@ARGV;