[Reproducible-commits] [dpkg] 30/90: Dpkg::Changelog::Parse: Factor out _changelog_detect_format

Jérémy Bobbio lunar at moszumanska.debian.org
Sat Aug 29 18:26:11 UTC 2015


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

lunar pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit c2c755d0924ef9aea32cd81ab7871fb511b2c2a5
Author: Guillem Jover <guillem at debian.org>
Date:   Sat Jul 25 06:26:25 2015 +0200

    Dpkg::Changelog::Parse: Factor out _changelog_detect_format
---
 scripts/Dpkg/Changelog/Parse.pm | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/scripts/Dpkg/Changelog/Parse.pm b/scripts/Dpkg/Changelog/Parse.pm
index cd0891a..d92a666 100644
--- a/scripts/Dpkg/Changelog/Parse.pm
+++ b/scripts/Dpkg/Changelog/Parse.pm
@@ -50,6 +50,27 @@ use Dpkg::Control::Changelog;
 
 =over 4
 
+=cut
+
+sub _changelog_detect_format {
+    my $file = shift;
+    my $format = 'debian';
+
+    # Extract the format from the changelog file if possible
+    if ($file ne '-') {
+        local $_;
+
+        open my $format_fh, '-|', 'tail', '-n', '40', $file
+            or syserr(g_('cannot create pipe for %s'), 'tail');
+        while (<$format_fh>) {
+            $format = $1 if m/\schangelog-format:\s+([0-9a-z]+)\W/;
+        }
+        close $format_fh or subprocerr(g_('tail of %s'), $file);
+    }
+
+    return $format;
+}
+
 =item $fields = changelog_parse_plugin(%opt)
 
 This function will parse a changelog. In list context, it returns as many
@@ -88,8 +109,7 @@ sub changelog_parse_plugin {
     my @parserpath = ('/usr/local/lib/dpkg/parsechangelog',
                       "$Dpkg::LIBDIR/parsechangelog",
                       '/usr/lib/dpkg/parsechangelog');
-    my $format = 'debian';
-    my $force = 0;
+    my $format;
 
     # Extract and remove options that do not concern the changelog parser
     # itself (and that we shouldn't forward)
@@ -100,19 +120,8 @@ sub changelog_parse_plugin {
     if (exists $options{changelogformat}) {
 	$format = $options{changelogformat};
 	delete $options{changelogformat};
-	$force = 1;
-    }
-
-    # Extract the format from the changelog file if possible
-    unless ($force or ($changelogfile eq '-')) {
-	local $_;
-
-	open(my $format_fh, '-|', 'tail', '-n', '40', $changelogfile)
-	    or syserr(g_('cannot create pipe for %s'), 'tail');
-	while (<$format_fh>) {
-	    $format = $1 if m/\schangelog-format:\s+([0-9a-z]+)\W/;
-	}
-	close($format_fh) or subprocerr(g_('tail of %s'), $changelogfile);
+    } else {
+	$format = _changelog_detect_format($changelogfile);
     }
 
     # Find the right changelog parser

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list