summaryrefslogtreecommitdiff
path: root/system/stow/merge.diff
blob: 1ee166872ddb9a4985e2a93e1d1e906d69e07182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Avoid using Hash::Merge.

stow 2.3.0 added external dependencies on Hash::Merge and Clone::Choose, which
makes bootstrapping awkward. It's not actually using most of Hash::Merge's
features, so replace it with a specialised merge routine.

diff -x config.guess -x config.log -x config.status -x config.sub -ru tmp/stow-2.3.0/Build.PL work/stow-2.3.0/Build.PL
--- tmp/stow-2.3.0/Build.PL	2019-06-28 23:51:12.000000000 +0100
+++ work/stow-2.3.0/Build.PL	2019-06-29 12:05:59.195616482 +0100
@@ -60,8 +60,6 @@
         'perl'        => '5.006',
         'Carp'        => 0,
         'IO::File'    => 0,
-        'Hash::Merge' => 0,
-        'Clone'       => 0,
     },
     script_files => [ 'bin/stow', 'bin/chkstow' ],
     all_from => 'lib/Stow.pm.in',
diff -x config.guess -x config.log -x config.status -x config.sub -ru tmp/stow-2.3.0/bin/stow.in work/stow-2.3.0/bin/stow.in
--- tmp/stow-2.3.0/bin/stow.in	2019-06-28 23:33:58.000000000 +0100
+++ work/stow-2.3.0/bin/stow.in	2019-06-29 12:25:50.098558041 +0100
@@ -457,16 +457,12 @@

 use POSIX qw(getcwd);
 use Getopt::Long qw(GetOptionsFromArray);
+use Scalar::Util qw(reftype);

 @USE_LIB_PMDIR@
 use Stow;
 use Stow::Util qw(parent error);

-# Need to avoid Storable backend, since it can't deal with regexps:
-# https://rt.perl.org/Public/Bug/Display.html?id=50608
-use Clone::Choose qw(:Clone);
-use Hash::Merge qw(merge);
-
 my $ProgramName = $0;
 $ProgramName =~ s{.*/}{};

@@ -530,17 +526,27 @@

     # Merge .stowrc and command line options.
     # Preference is given to cli options.
-    # rc options come first in merged arrays.
-    # cli options overwrite conflicting rc options.
-    Hash::Merge::set_behavior('RIGHT_PRECEDENT');
-    my $options = merge($rc_options, $cli_options);
+    my %options = %$rc_options;
+    foreach my $option (keys %$cli_options) {
+        my $rc_value = $rc_options->{$option};
+        my $cli_value = $cli_options->{$option};
+        my $type = reftype($cli_value);
+
+        if (defined $type && $type eq 'ARRAY' && defined $rc_value) {
+            # rc options come first in merged arrays.
+            $options{$option} = [@{$rc_value}, @{$cli_value}];
+        } else {
+            # cli options overwrite conflicting rc options.
+            $options{$option} = $cli_value;
+        }
+    }

     # Run checks on the merged options.
-    sanitize_path_options($options);
+    sanitize_path_options(\%options);
     check_packages($pkgs_to_unstow, $pkgs_to_stow);

     # Return merged and processed options.
-    return ($options, $pkgs_to_unstow, $pkgs_to_stow);
+    return (\%options, $pkgs_to_unstow, $pkgs_to_stow);
 }

 #===== SUBROUTINE ===========================================================