summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bremner <bremner@debian.org>2018-10-06 15:59:58 -0300
committerDavid Bremner <bremner@debian.org>2018-10-06 16:04:45 -0300
commite4334e2d4ada310009877eabb1d4f14eff671a45 (patch)
tree9afde6a70d2df9890d2683d33a77d20cb81c0c61
parent608f05bf99158c87106fd4b21a11fab056b8cf5a (diff)
refactor doublearray parsing code
Replace a pair of parallel arrays @files, @dests with a single array of hashes (@actions). Replace repeated in place modification of @files with a more "functional" style, building @actions from @lines, which is roughly the raw input. Replace nested map with map inside for loop.
-rwxr-xr-xdh_elpa.in51
1 files changed, 31 insertions, 20 deletions
diff --git a/dh_elpa.in b/dh_elpa.in
index 3376612..7b960d2 100755
--- a/dh_elpa.in
+++ b/dh_elpa.in
@@ -225,35 +225,47 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
}
verbose_print("Using elpa package name $elpapkg");
- my @files;
- my @dests;
+ my @lines;
+ my @actions;
my $is_single_file;
+ my $has_package_file = 0;
# Call isnative because it sets $dh{VERSION}
# as a side effect.
isnative($package);
if ($file) {
- # Don't glob yet, we need to count the words first.
- @files=filedoublearray($file);
+ # Read in the contents of the elpa control file into an array of
+ # arrays. Don't glob yet, we need to count the words first.
+ @lines=filedoublearray($file);
+
+ foreach my $line (@lines) {
+ my $action = {};
+ # On lines with more than one word, the last word is the
+ # destination (sub)directory
+ if (@$line >1) {
+ $action->{dest} = pop(@$line);
+ }
+
+ # Glob expand every word in the current line
+ $action->{src} = [ map { glob_expand(["."], \&glob_expand_error_handler_warn_and_discard, $_) } @$line ];
- # On lines with more than one word, the last word is the
- # destination (sub)directory
- @dests=map { (@$_ > 1) ? (pop @$_) : undef; } @files;
+ # Check for an multi-file elpa package control file
+ $has_package_file ||= (grep m/\b${elpapkg}-pkg.el$/, @{$action->{src}});
- # Globexpand any remaining words, leaving them grouped as one array per line.
- @files=map { map { [ glob_expand(["."], \&glob_expand_error_handler_warn_and_discard, $_) ] } @$_ } @files;
+ push @actions, $action;
+ }
- $is_single_file = (scalar(@files) == 1 && scalar(@{$files[0]}) == 1);
+ $is_single_file = (scalar(@actions) == 1 && scalar(@{$actions[0]->{src}}) == 1);
- $is_single_file || grep { $_[0] =~ m/\b${elpapkg}-pkg.el$/ } @files or
- warning "missing ${elpapkg}-pkg.el; will try to generate it";
+ warning "missing ${elpapkg}-pkg.el; will try to generate it"
+ unless ($is_single_file || $has_package_file);
}
if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL})
&& @ARGV) {
- push @files, @ARGV;
+ push @actions, map { {"src" => $_} } @ARGV;
}
- next PACKAGE if (scalar(@files) == 0);
+ next PACKAGE if (scalar(@actions) == 0);
my $pkg_file;
my $cwd = getcwd();
@@ -278,7 +290,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
error "creating $tempdir";
if ($is_single_file) {
- my $pkg_file=$files[0][0];
+ my $pkg_file=${$actions[0]->{src}}[0];
doit_quietly(qw{emacs -batch -Q -l package},
'--eval',"(add-to-list 'package-directory-list \"$dhelpadir\")",
@@ -287,18 +299,17 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
qw{-f dhelpa-batch-install-file}, "$tmp/$elpadir", $pkg_file, @extra_args);
} else {
my $stagedir = "$tempdir/$elpapkg";
- for (my $i=0; $i<scalar(@files); $i++) {
+ foreach my $action (@actions) {
my $targetdir = $stagedir;
- if (defined ($dests[$i])) {
- verbose_print("dest=$dests[$i]");
- $targetdir = $stagedir . "/" . $dests[$i];
+ if (defined ($action->{dest})) {
+ $targetdir = $stagedir . "/" . $action->{dest};
}
File::Path::make_path $targetdir ||
error "creating $targetdir";
- foreach my $file (@{$files[$i]}) {
+ foreach my $file (@{$action->{src}}) {
doit("cp", "-a", $file, "$targetdir");
}
}