chiark / gitweb /
Tag change: Declare intent in docs etc.
[dgit.git] / Debian / Dgit.pm
index 2555812c46abcdd1c617e718b0cb1c5643e8e0ba..fb983c1a023b2e44d49048255c89dd3ea7797e4a 100644 (file)
@@ -5,10 +5,12 @@ package Debian::Dgit;
 use strict;
 use warnings;
 
+use Carp;
 use POSIX;
 use IO::Handle;
 use Config;
 use Digest::SHA;
+use Data::Dumper;
 
 BEGIN {
     use Exporter   ();
@@ -17,7 +19,7 @@ BEGIN {
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(setup_sigwarn
-                      debiantag server_branch server_ref
+                      debiantag_old debiantag_new server_branch server_ref
                       stat_exists link_ltarget
                      hashfile
                       fail ensuredir executable_on_path
@@ -123,12 +125,18 @@ sub debugcmd {
     printcmd(\*DEBUG,$debugprefix.$extraprefix,@_) if $debuglevel>0;
 }
 
-sub debiantag ($$) { 
+sub debiantag_old ($$) { 
     my ($v,$distro) = @_;
     $v =~ y/~:/_%/;
     return "$distro/$v";
 }
 
+sub debiantag_new ($$) { 
+    my ($v,$distro) = @_;
+    $v =~ y/~:/_%/;
+    return "archive/$distro/$v";
+}
+
 sub server_branch ($) { return "$branchprefix/$_[0]"; }
 sub server_ref ($) { return "refs/".server_branch($_[0]); }
 
@@ -186,8 +194,19 @@ sub waitstatusmsg () {
 }
 
 sub failedcmd {
+    # Expects $!,$? as set by close - see below.
+    # To use with system(), set $?=-1 first.
+    #
+    # Actual behaviour of perl operations:
+    #   success              $!==0       $?==0       close of piped open
+    #   program failed       $!==0       $? >0       close of piped open
+    #   syscall failure      $! >0       $?=-1       close of piped open
+    #   failure              $! >0       unchanged   close of something else
+    #   success              trashed     $?==0       system
+    #   program failed       trashed     $? >0       system
+    #   syscall failure      $! >0       unchanged   system
     { local ($!); printcmd \*STDERR, _us().": failed command:", @_ or die $!; };
-    if ($!) {
+    if ($? < 0) {
        fail "failed to fork/exec: $!";
     } elsif ($?) {
        fail "subprocess ".waitstatusmsg();
@@ -197,7 +216,7 @@ sub failedcmd {
 }
 
 sub cmdoutput_errok {
-    die Dumper(\@_)." ?" if grep { !defined } @_;
+    confess Dumper(\@_)." ?" if grep { !defined } @_;
     debugcmd "|",@_;
     open P, "-|", @_ or die "$_[0] $!";
     my $d;