[devscripts] 04/09: mk-origtargz: Use Dpkg modules to parse changelog/version

James McCoy jamessan at debian.org
Thu Apr 24 04:40:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

jamessan pushed a commit to branch master
in repository devscripts.

commit c457d82bc83f001a52588243215cecd1c6f108b1
Author: James McCoy <jamessan at debian.org>
Date:   Mon Apr 21 10:36:49 2014 -0400

    mk-origtargz: Use Dpkg modules to parse changelog/version
    
    Signed-off-by: James McCoy <jamessan at debian.org>
---
 scripts/mk-origtargz.pl | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/scripts/mk-origtargz.pl b/scripts/mk-origtargz.pl
index 925e296..9840d70 100755
--- a/scripts/mk-origtargz.pl
+++ b/scripts/mk-origtargz.pl
@@ -154,7 +154,9 @@ use File::Temp qw/tempdir/;
 use Getopt::Long qw(:config gnu_getopt);
 use Pod::Usage;
 
+use Dpkg::Changelog::Debian;
 use Dpkg::IPC;
+use Dpkg::Version;
 use File::Spec;
 
 BEGIN { push(@INC, '/usr/share/devscripts') } # append to @INC, so that -I . has precedence
@@ -240,23 +242,22 @@ $upstream = $ARGV[0];
 
 unless (defined $package) {
     # get package name
-    open F, "debian/changelog" or die "debian/changelog: $!\n";
-    my $line = <F>;
-    close F;
-    unless ($line =~ /^(\S+) \((\S+)\)/) {
-	die "could not parse debian/changelog:1: $line";
+    my $c = Dpkg::Changelog::Debian->new(range => { count => 1 });
+    $c->load('debian/changelog');
+    if (my $msg = $c->get_parse_errors()) {
+	die "could not parse debian/changelog:\n$msg";
     }
-    $package = $1;
+    my ($entry) = @{$c};
+    $package = $entry->get_source();
 
     # get version number
     unless (defined $version) {
-	$version = $2;
-	unless ($version =~ /-/) {
-	    print "Package with native version number $version; mk-origtargz makes no sense for native packages.\n";
+	my $debversion = Dpkg::Version->new($entry->get_version());
+	if ($debversion->is_native()) {
+	    print "Package with native version number $debversion; mk-origtargz makes no sense for native packages.\n";
 	    exit 0;
 	}
-	$version =~ s/(.*)-.*/$1/; # strip everything from the last dash
-	$version =~ s/^\d+://; # strip epoch
+	$version = $debversion->version();
     }
 
     unshift @copyright_files, "debian/copyright" if -r "debian/copyright";

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git



More information about the devscripts-devel mailing list