/contrib/cvs/contrib/cln_hist.in

https://bitbucket.org/freebsd/freebsd-head/ · Autoconf · 103 lines · 46 code · 15 blank · 42 comment · 16 complexity · 57a90147f2d849b46206e11113c97027 MD5 · raw file

  1. #! @PERL@
  2. # -*-Perl-*-
  3. # Copyright (C) 1995-2005 The Free Software Foundation, Inc.
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # Contributed by David G. Grubbs <dgg@ksr.com>
  15. #
  16. # Clean up the history file. 10 Record types: MAR OFT WUCG
  17. #
  18. # WUCG records are thrown out.
  19. # MAR records are retained.
  20. # T records: retain only last tag with same combined tag/module.
  21. #
  22. # Two passes: Walk through the first time and remember the
  23. # 1. Last Tag record with same "tag" and "module" names.
  24. # 2. Last O record with unique user/module/directory, unless followed
  25. # by a matching F record.
  26. #
  27. $r = $ENV{"CVSROOT"};
  28. $c = "$r/CVSROOT";
  29. $h = "$c/history";
  30. eval "print STDERR \$die='Unknown parameter $1\n' if !defined \$$1; \$$1=\$';"
  31. while ($ARGV[0] =~ /^(\w+)=/ && shift(@ARGV));
  32. exit 255 if $die; # process any variable=value switches
  33. %tags = ();
  34. %outs = ();
  35. #
  36. # Move history file to safe place and re-initialize a new one.
  37. #
  38. rename($h, "$h.bak");
  39. open(XX, ">$h");
  40. close(XX);
  41. #
  42. # Pass1 -- remember last tag and checkout.
  43. #
  44. open(HIST, "$h.bak");
  45. while (<HIST>) {
  46. next if /^[MARWUCG]/;
  47. # Save whole line keyed by tag|module
  48. if (/^T/) {
  49. @tmp = split(/\|/, $_);
  50. $tags{$tmp[4] . '|' . $tmp[5]} = $_;
  51. }
  52. # Save whole line
  53. if (/^[OF]/) {
  54. @tmp = split(/\|/, $_);
  55. $outs{$tmp[1] . '|' . $tmp[2] . '|' . $tmp[5]} = $_;
  56. }
  57. }
  58. #
  59. # Pass2 -- print out what we want to save.
  60. #
  61. open(SAVE, ">$h.work");
  62. open(HIST, "$h.bak");
  63. while (<HIST>) {
  64. next if /^[FWUCG]/;
  65. # If whole line matches saved (i.e. "last") one, print it.
  66. if (/^T/) {
  67. @tmp = split(/\|/, $_);
  68. next if $tags{$tmp[4] . '|' . $tmp[5]} ne $_;
  69. }
  70. # Save whole line
  71. if (/^O/) {
  72. @tmp = split(/\|/, $_);
  73. next if $outs{$tmp[1] . '|' . $tmp[2] . '|' . $tmp[5]} ne $_;
  74. }
  75. print SAVE $_;
  76. }
  77. #
  78. # Put back the saved stuff
  79. #
  80. system "cat $h >> $h.work";
  81. if (-s $h) {
  82. rename ($h, "$h.interim");
  83. print "history.interim has non-zero size.\n";
  84. } else {
  85. unlink($h);
  86. }
  87. rename ("$h.work", $h);
  88. exit(0);