From d22ab2d47a448ff3238a93b763b86a3977af651c Mon Sep 17 00:00:00 2001 From: John McQuah Date: Tue, 20 Jun 2023 15:49:52 -0400 Subject: [PATCH] new data structures to keep track of dups --- scripts/pkg-repgen.pl | 60 ++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/scripts/pkg-repgen.pl b/scripts/pkg-repgen.pl index 858fcf8..de9086c 100755 --- a/scripts/pkg-repgen.pl +++ b/scripts/pkg-repgen.pl @@ -29,20 +29,29 @@ $compress =~ s/["' ]//g; $prtget .= " --no-std-config --config-set=\"prtdir $prtdir\"" if ($prtdir); -my @dirlist = glob("*#*.pkg.tar.$compress"); my @packages; +my @dirlist = glob("*#*.pkg.tar.$compress"); +my @packages; my %isDup; + if ($#ARGV >= 0) { # single packages foreach my $name (sort @ARGV) { my @hits = glob("$name#*.pkg.tar.$compress"); push(@packages,@hits); + $isDup{$name} = 1 if ($#hits > 0); } } else { @packages = @dirlist; } -# A hash to determine quickly whether a package is a dup +# hashes to determine the package name ... our %pname = map { $_ => $_ } @packages; foreach my $p (@packages) { $pname{$p} =~ s/\#.*//; } +# ... or to look up the successor when merging old metadata files +my %followR; my %followH; my @queue = @packages; +while (my $q = shift @queue) { + ($#queue < 0) or ($pname{$q} ne $pname{$queue[0]}) or $isDup{$q} = 1; +} + # Populate some other hashes using a single run of prt-get our %path; our %depends; our %descrip; our %flags; my @validkeys = @dirlist; @@ -91,7 +100,6 @@ sub pkg_single { while (my $p =shift @packages) { my ($pver, $url, $du, $md5, $desc, $ppr, $pdeps, $date) = metadata($p); - my $isDup = ((@packages) and ($pname{$packages[0]} eq $pname{$p})) ? 1 : 0; ($firstrun{"PKGREPO"}==0) or printf $nR "%-s:%-s:%-s:%-s:%-s\n", $p, $du, $md5, $desc, $ppr; @@ -99,7 +107,7 @@ sub pkg_single { or printf $nD "%-30s : %-s\n", $pname{$p}, $pdeps; if ($firstrun{"index.html"} == 1) { $count++; - htmlrow($nH,$parity{($count % 2)},$pname{$p},$url,$pver,$desc,$date); + htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date); } # Pop entries from the old repository until we reach an entry @@ -107,7 +115,7 @@ sub pkg_single { while ( ($firstrun{"PKGREPO"}==0) and $oline = <$oR> ) { chomp($oline); $oname = $oline; $oname =~ s/\#.*//; - print $nR "$oline\n" if ($oname lt $pname{$p}); + print $nR "$oline\n" if ($oname lt $pname{$p}); # before breaking out of the loop, either overwrite the old # entry in the repository, or insert the requested package @@ -115,10 +123,8 @@ sub pkg_single { printf $nR "%-s:%-s:%-s:%-s:%-s\n", $p, $du, $md5, $desc, $ppr if ($oname ge $pname{$p}); - # in case the current package is the last in a sequence of dups, or - # the last in the queue, make sure we don't lose what got popped - # from the repository - print $nR $oline if (($oname gt $pname{$p}) and (! $isDup)); + # save what got popped from the repository, in case of dups + $followR{$pname{$p}} = $oline if ($oname gt $pname{$p}); # stop reading the repository, at least until the next package last if ($oname ge $pname{$p}); @@ -135,25 +141,28 @@ sub pkg_single { $oname =~ s/.*a href="(.*)"/$1/; $oname =~ s/\%23.*//; - print $nH "$oline\n" if ($oname lt $pname{$p}); - htmlrow($nH,$parity{($count % 2)},$pname{$p},$url,$pver,$desc,$date) - if ($oname ge $pname{$p}); - - if ( ($oname gt $pname{$p}) and (! $isDup) ) { - $count++; - $oline =~ s/class="(even|odd)"/class="$parity{($count %2)}"/; - print $nH "$oline\n"; - } + print $nH "$oline\n" if ($oname lt $pname{$p}); + htmlrow($nH,$count,$pname{$p},$url, + $pver,$desc,$date) if ($oname ge $pname{$p}); + $followH{$pname{$p}} = $oline if ($oname gt $pname{$p}); last if ($oname ge $pname{$p}); } + if ( (! $isDup{$p}) and ($isDup{$pname{$p}}) ) { + $count++; + (! $followH{$pname{$p}}) or $followH{$pname{$p}} =~ + s/class="(even|odd)"/class="$parity{($count %2)}"/; + (! $followH{$pname{$p}}) or print $nH $followH{$pname{$p}}; + (! $followR{$pname{$p}}) or print $nR $followR{$pname{$p}}; + } + # Likewise for the dependency map, but avoid creating duplicate entries while ($firstrun{"PKGDEPS"}==0 and $oline = <$oD>) { chomp($oline); $oname = $oline; $oname =~ s/\s*\:.*//; if ($oname lt $pname{$p}) { print $nD "$oline\n"; - } elsif ( ($pdeps ne "") and (! $isDup) ) { + } elsif ( ($pdeps ne "") and (! $isDup{$p}) ) { printf $nD "%-30s : %-s\n", $pname{$p}, $pdeps; } printf $nD "$oline\n" if ($oname gt $pname{$p}); @@ -193,15 +202,14 @@ sub pkg_dir { printheader(0); my $count = 0; open (my $ih, '>>index.html'); - while (my $p =shift @packages) { + foreach my $p (@packages) { chomp($p); $count++; my ($pver, $url, $du, $md5, $desc, $ppr, $pdeps, $date) = metadata($p); - ($pdeps eq "") or - ( (@packages) and ($pname{$p} eq $pname{$packages[0]}) ) - or printf $iD "%-30s : %-s\n", $pname{$p}, $pdeps; + ($pdeps eq "") or ($isDup{$p}) or (! $isDup{$pname{$p}}) + or printf $iD "%-30s : %-s\n", $pname{$p}, $pdeps; printf $iR "%-s:%-s:%-s:%-s:%-s\n", $p,$du,$md5,$desc,$ppr; - htmlrow($ih,$parity{($count % 2)},$pname{$p},$url,$pver,$desc,$date); + htmlrow($ih,$count,$pname{$p},$url,$pver,$desc,$date); } close($ih); printfooter($count); @@ -321,8 +329,8 @@ EOH } sub htmlrow { - my ($ih, $odd, $name, $url, $version, $desc, $date) = @_; - print $ih "$name"; + my ($ih, $count, $name, $url, $version, $desc, $date) = @_; + print $ih "$name"; print $ih "$version"; print $ih "$desc$date\n"; }