#!/usr/bin/perl

use strict;
use warnings;

use Debian::Debhelper::Dh_Lib;
init(options => { 'pristine-tar' => \$dh{PRISTINE_TAR } } );

my $source_pkg = sourcepackage();
my $is_native  = isnative($source_pkg);
my $verbose    = $dh{VERBOSE};
my $pristine_tar = $dh{PRISTINE_TAR};
my $upstream_version = $dh{VERSION};
# Strip Debian revision
$upstream_version =~ s/-[^-]+$//;

my $orig_tar = "../${source_pkg}_${upstream_version}.orig.tar";
doit('tar',
     ($verbose ? 'cvf' : 'cf'),
     $orig_tar,
     ($is_native ? '' : '--exclude=debian'),
     qw(--exclude=.git --exclude=.svn --exclude=.hg .),
     @ARGV);
doit('xz', '-7f'.($verbose ? 'v' : ''), $orig_tar);
if ($pristine_tar) {
    doit(qw(pristine-tar commit), ($verbose ? '-v' : ()), "${orig_tar}.xz");
}

=head1 NAME

dh_dist_zilla_origtar - debhelper add-on to generate an upstream tar ball

=head1 DESCRIPTION

dh_dist_zilla_origtar is the backend for the dh-dist-zilla's C<dh
get-orig-source> target to generate minimal upstream tar-balls
suitable for use with dh-dist-zilla.

=head1 OPTIONS

C<--pristine-tar>: Also commit generated upstream tar ball to
pristine-tar branch using pristine-tar.

Options before C<--> are used by debhelper.  Options after C<--> are passed on to C<tar>.

=head1 SEE ALSO

L<dh(1)>, L<debhelper(7)>, L<dh-dist-zilla(7)>

=head1 AUTHOR

Axel Beckert <abe@debian.org>
