[Libreoffice-commits] .: 6 commits - solenv/bin

Michael Meeks michael at kemper.freedesktop.org
Thu Feb 16 05:47:56 PST 2012


 solenv/bin/make_installer.pl                    |    8 +-
 solenv/bin/modules/installer/sorter.pm          |   89 +++---------------------
 solenv/bin/modules/installer/windows/feature.pm |   13 +--
 solenv/bin/modules/installer/worker.pm          |   20 -----
 solenv/bin/modules/t/installer-sorter.t         |   48 ++++++++++++
 5 files changed, 71 insertions(+), 107 deletions(-)

New commits:
commit 51f8f151780b6514d515b739e3167f36eb30787c
Author: Tim Retout <tim at retout.co.uk>
Date:   Wed Feb 15 20:08:57 2012 +0000

    Simplify installer::sorter::sorting_array_of_hashes.

diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm
index 54e5c34..b08dd80 100644
--- a/solenv/bin/modules/installer/sorter.pm
+++ b/solenv/bin/modules/installer/sorter.pm
@@ -44,26 +44,10 @@ sub sorting_array_of_hashes
 {
     my ($arrayref, $sortkey) = @_;
 
-    for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
-    {
-        my $onehashunder = ${$arrayref}[$i];
-        my $sortvalueunder = $onehashunder->{$sortkey};
-
-        for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ )
-        {
-            my $onehashover = ${$arrayref}[$j];
-            my $sortvalueover = $onehashover->{$sortkey};
-
-            if ( $sortvalueunder gt $sortvalueover)
-            {
-                ${$arrayref}[$i] = $onehashover;
-                ${$arrayref}[$j] = $onehashunder;
-
-                $onehashunder = $onehashover;
-                $sortvalueunder = $sortvalueover;
-            }
-        }
-    }
+    @$arrayref = map { $_->[1] }
+                 sort { $a->[0] cmp $b->[0] }
+                 map { [$_->{$sortkey}, $_] }
+                 @$arrayref;
 }
 
 1;
commit 01fde2e939cbc4aeeb15978febb5e2fa0396c125
Author: Tim Retout <tim at retout.co.uk>
Date:   Wed Feb 15 19:00:10 2012 +0000

    Add tests for installer::sorter

diff --git a/solenv/bin/modules/t/installer-sorter.t b/solenv/bin/modules/t/installer-sorter.t
new file mode 100644
index 0000000..fe67b4e
--- /dev/null
+++ b/solenv/bin/modules/t/installer-sorter.t
@@ -0,0 +1,48 @@
+# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License or as specified alternatively below. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# Major Contributor(s):
+# [ Copyright (C) 2012 Tim Retout <tim at retout.co.uk> (initial developer) ]
+#
+# All Rights Reserved.
+#
+# For minor contributions see the git repository.
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.
+
+use strict;
+use warnings;
+
+use lib '.';
+
+use Test::More;
+use List::Util 'shuffle';
+
+BEGIN {
+    use_ok('installer::sorter', qw(
+        sorting_array_of_hashes
+    ));
+}
+
+my @loh_str_sorted = map { { "key" => $_ } } ("a".."j");
+
+my @loh_str_random = shuffle @loh_str_sorted;
+
+sorting_array_of_hashes(\@loh_str_random, "key");
+
+is_deeply(\@loh_str_random, \@loh_str_sorted);
+
+done_testing();
commit a1bc2d7d23e160bd9bb9570b4d512eee740aca15
Author: Tim Retout <tim at retout.co.uk>
Date:   Wed Feb 15 18:50:06 2012 +0000

    Use Exporter for installer::sorter

diff --git a/solenv/bin/make_installer.pl b/solenv/bin/make_installer.pl
index 4f35aed..45dede0 100644
--- a/solenv/bin/make_installer.pl
+++ b/solenv/bin/make_installer.pl
@@ -57,7 +57,7 @@ use installer::scpzipfiles;
 use installer::scriptitems;
 use installer::setupscript;
 use installer::simplepackage;
-use installer::sorter;
+use installer::sorter qw(sorting_array_of_hashes);
 use installer::strip;
 use installer::substfilenamefiles;
 use installer::systemactions;
@@ -1101,7 +1101,7 @@ for ( my $n = 0; $n <= $#installer::globals::languageproducts; $n++ )
         if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3alangpack.log", $directoriesforepmarrayref); }
         ($directoriesforepmarrayref, $alldirectoryhash) = installer::scriptitems::collect_directories_with_create_flag_from_directoryarray($dirsinproductlanguageresolvedarrayref, $alldirectoryhash);
         if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3blangpack.log", $directoriesforepmarrayref); }
-        installer::sorter::sorting_array_of_hashes($directoriesforepmarrayref, "HostName");
+        sorting_array_of_hashes($directoriesforepmarrayref, "HostName");
         if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3clangpack.log", $directoriesforepmarrayref); }
 
         if ( $installer::globals::iswindowsbuild )
@@ -1130,7 +1130,7 @@ for ( my $n = 0; $n <= $#installer::globals::languageproducts; $n++ )
         if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3ahelppack.log", $directoriesforepmarrayref); }
         ($directoriesforepmarrayref, $alldirectoryhash) = installer::scriptitems::collect_directories_with_create_flag_from_directoryarray($dirsinproductlanguageresolvedarrayref, $alldirectoryhash);
         if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3bhelppack.log", $directoriesforepmarrayref); }
-        installer::sorter::sorting_array_of_hashes($directoriesforepmarrayref, "HostName");
+        sorting_array_of_hashes($directoriesforepmarrayref, "HostName");
         if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3chelppack.log", $directoriesforepmarrayref); }
 
         if ( $installer::globals::iswindowsbuild )
@@ -1171,7 +1171,7 @@ for ( my $n = 0; $n <= $#installer::globals::languageproducts; $n++ )
             ($directoriesforepmarrayref, $alldirectoryhash) = installer::scriptitems::collect_directories_from_filesarray($filesinproductlanguageresolvedarrayref);
             if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist4_patch.log", $directoriesforepmarrayref); }
 
-            installer::sorter::sorting_array_of_hashes($directoriesforepmarrayref, "HostName");
+            sorting_array_of_hashes($directoriesforepmarrayref, "HostName");
             if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist5_patch.log", $directoriesforepmarrayref); }
         }
     }
diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm
index 91ed9ae..54e5c34 100644
--- a/solenv/bin/modules/installer/sorter.pm
+++ b/solenv/bin/modules/installer/sorter.pm
@@ -30,6 +30,12 @@ package installer::sorter;
 use strict;
 use warnings;
 
+use base 'Exporter';
+
+our @EXPORT_OK = qw(
+    sorting_array_of_hashes
+);
+
 #########################################
 # Sorting an array of hashes
 #########################################
commit 94c1836fb5e2028a237d5104115090c81667e1db
Author: Tim Retout <tim at retout.co.uk>
Date:   Wed Feb 15 19:55:46 2012 +0000

    Inline and simplify installer::sorter::sort_array_of_hashes_numerically.

diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm
index b61bb5b..91ed9ae 100644
--- a/solenv/bin/modules/installer/sorter.pm
+++ b/solenv/bin/modules/installer/sorter.pm
@@ -60,34 +60,4 @@ sub sorting_array_of_hashes
     }
 }
 
-######################################################
-# Sorting an array of hashes with a numerical value
-######################################################
-
-sub sort_array_of_hashes_numerically
-{
-    my ($arrayref, $sortkey) = @_;
-
-    for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
-    {
-        my $onehashunder = ${$arrayref}[$i];
-        my $sortvalueunder = $onehashunder->{$sortkey};
-
-        for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ )
-        {
-            my $onehashover = ${$arrayref}[$j];
-            my $sortvalueover = $onehashover->{$sortkey};
-
-            if ( $sortvalueunder > $sortvalueover)
-            {
-                ${$arrayref}[$i] = $onehashover;
-                ${$arrayref}[$j] = $onehashunder;
-
-                $onehashunder = $onehashover;
-                $sortvalueunder = $sortvalueover;
-            }
-        }
-    }
-}
-
 1;
diff --git a/solenv/bin/modules/installer/windows/feature.pm b/solenv/bin/modules/installer/windows/feature.pm
index d570ec0..92d8cfe 100644
--- a/solenv/bin/modules/installer/windows/feature.pm
+++ b/solenv/bin/modules/installer/windows/feature.pm
@@ -31,7 +31,6 @@ use installer::existence;
 use installer::exiter;
 use installer::files;
 use installer::globals;
-use installer::sorter;
 use installer::worker;
 use installer::windows::idtglobal;
 use installer::windows::language;
@@ -244,8 +243,7 @@ sub collect_modules_recursive
     {
         if ( $directparent->{$modulegid} eq $parentid )
         {
-            my %childhash = ( "gid" => "$modulegid", "Sortkey" => "$directsortkey->{$modulegid}");
-            push(@allchildren, \%childhash);
+            push @allchildren, [ $directsortkey->{$modulegid}, $modulegid ];
             $childrenexist = 1;
         }
     }
@@ -255,14 +253,13 @@ sub collect_modules_recursive
     if ( $childrenexist )
     {
         # Sort children
-        installer::sorter::sort_array_of_hashes_numerically(\@allchildren, "Sortkey");
+        @allchildren = map { $_->[1] }
+                       sort { $a->[0] <=> $b->[0] }
+                       @allchildren;
 
         # Adding children to new array
-        my $childhashref;
-        foreach $childhashref ( @allchildren )
+        foreach my $gid ( @allchildren )
         {
-            my $gid = $childhashref->{'gid'};
-
             # Saving all lines, that have this 'gid'
 
             my $unique;
commit 14e6a83cc53438a360656449c8c5da41d46f9d87
Author: Tim Retout <tim at retout.co.uk>
Date:   Wed Feb 15 19:17:04 2012 +0000

    Remove unnecessary sorting subroutines.

diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm
index 4f3b9eb..b61bb5b 100644
--- a/solenv/bin/modules/installer/sorter.pm
+++ b/solenv/bin/modules/installer/sorter.pm
@@ -90,30 +90,4 @@ sub sort_array_of_hashes_numerically
     }
 }
 
-#########################################
-# Sorting an array of of strings
-#########################################
-
-sub sorting_array_of_strings
-{
-    my ($arrayref) = @_;
-
-    for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
-    {
-        my $onestringunder = ${$arrayref}[$i];
-
-        for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ )
-        {
-            my $onestringover = ${$arrayref}[$j];
-
-            if ( $onestringunder gt $onestringover)
-            {
-                ${$arrayref}[$i] = $onestringover;
-                ${$arrayref}[$j] = $onestringunder;
-                $onestringunder = $onestringover;
-            }
-        }
-    }
-}
-
 1;
diff --git a/solenv/bin/modules/installer/worker.pm b/solenv/bin/modules/installer/worker.pm
index c91ece7..445f1dc 100644
--- a/solenv/bin/modules/installer/worker.pm
+++ b/solenv/bin/modules/installer/worker.pm
@@ -42,7 +42,6 @@ use installer::logger;
 use installer::pathanalyzer;
 use installer::scpzipfiles;
 use installer::scriptitems;
-use installer::sorter;
 use installer::systemactions;
 use installer::windows::language;
 
@@ -1533,23 +1532,6 @@ sub shift_file_to_end
 }
 
 ###########################################################
-# Putting hash content into array and sorting it
-###########################################################
-
-sub sort_hash
-{
-    my ( $hashref ) =  @_;
-
-    my $item = "";
-    my @sortedarray = ();
-
-    foreach $item (keys %{$hashref}) { push(@sortedarray, $item); }
-    installer::sorter::sorting_array_of_strings(\@sortedarray);
-
-    return \@sortedarray;
-}
-
-###########################################################
 # Renaming Windows files in Patch and creating file
 # patchfiles.txt
 ###########################################################
@@ -1611,7 +1593,7 @@ sub prepare_windows_patchfiles
     my $patchlistfile = installer::existence::get_specified_file_by_name($filesref, $patchfilename);
 
     # reorganizing the patchfile content, sorting for directory to decrease the file size
-    my $sorteddirectorylist = sort_hash(\%patchfiledirectories);
+    my $sorteddirectorylist = [ sort keys %patchfiledirectories ];
     my $patchfilelist = reorg_patchfile(\@patchfiles, $sorteddirectorylist);
 
     # shifting version.ini to the end of the list, to guarantee, that all files are patched
commit 177a966630a792985626bfa37df20bcb755417ce
Author: Tim Retout <tim at retout.co.uk>
Date:   Wed Feb 15 18:02:44 2012 +0000

    Turn on strictures in installer::sorter

diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm
index dd983c0..4f3b9eb 100644
--- a/solenv/bin/modules/installer/sorter.pm
+++ b/solenv/bin/modules/installer/sorter.pm
@@ -27,6 +27,9 @@
 
 package installer::sorter;
 
+use strict;
+use warnings;
+
 #########################################
 # Sorting an array of hashes
 #########################################


More information about the Libreoffice-commits mailing list