mergeSolPatches.pl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/perl -w
  2. # --- BEGIN COPYRIGHT BLOCK ---
  3. # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  4. # Copyright (C) 2005 Red Hat, Inc.
  5. # All rights reserved.
  6. #
  7. # License: GPL (version 3 or any later version).
  8. # See LICENSE for details.
  9. # --- END COPYRIGHT BLOCK ---
  10. # take a solaris8 patch list and a solaris9 patch list and merge them
  11. # together, removing duplicates
  12. # we are looking for patches that have the same major revision
  13. # number and release OS. We only want to keep the one with the highest
  14. # minor revision number
  15. # key is the major patch number
  16. # the value is a hash ref which has two keys 'iminor' and 'val'
  17. # the value of key 'iminor' is the minor patch number
  18. # the system keeps track of all revisions (minor number) for each patch (major number)
  19. # we only want to list the highest revision, since on Solaris higher revisions include
  20. # and supersede lower revisions
  21. # the value of key 'val' is the string to print out
  22. %patches = ();
  23. @lines = ();
  24. for $file (@ARGV) {
  25. open IN, $file or die "Error: could not open $file: $!";
  26. while (<IN>) {
  27. if (/^\s*\{(\d+),(\d+),\d,(\d+),/) {
  28. $major = $1;
  29. $minor = $2;
  30. $rel = $3;
  31. my $h = { 'val' => $_ };
  32. $patches{$major}{$rel}{$minor} = $h;
  33. if (! $patches{$major}{$rel}{highestminor}) {
  34. $patches{$major}{$rel}{highestminor} = $minor;
  35. } elsif ($patches{$major}{$rel}{highestminor} <= $minor) { # highest minor rev is lt or eq new minor
  36. my $oldminor = $patches{$major}{$rel}{highestminor};
  37. $patches{$major}{$rel}{$oldminor}->{skip} = 1;
  38. $patches{$major}{$rel}{highestminor} = $minor;
  39. } elsif ($patches{$major}{$rel}{highestminor} > $minor) {
  40. # skip the new one
  41. $h->{skip} = 1;
  42. }
  43. push @lines, $h; # put a hash ref into lines
  44. } else {
  45. push @lines, $_; # put the scalar value into lines
  46. }
  47. }
  48. close IN;
  49. }
  50. for (@lines) {
  51. if (ref($_)) {
  52. if ($_->{skip}) {
  53. chomp $_->{val};
  54. print "/* duplicate or superseded ", $_->{val}, " */\n";
  55. } else {
  56. print $_->{val};
  57. }
  58. } else {
  59. print;
  60. }
  61. }