#!/usr/bin/perl # # This program will trim the CVS history file. It must be run by # somebody who can write to the CVSROOT directory in the actual # repository directory. # # It has two built-in numbers, the number of lines to leave the # history file at, and the number of lines the history file must # be to need trimming. The difference is the number of lines # created between trimmings. # # It will create a file called history.trim.?, where the ? is a # sequential number, and will write the trimmed-off part to that # file. It will create a new file, arbitrarily named, to write # the rest of the history file to, and then will unlink the previous # history file and rename the new file to "history". # #Copyright 2002, David H. Thornley. #Permission granted to use under Gnu General Public License, version 2 or later. #This license is available at http://www.thornleyweb.com/perl/license.html #No warranty, express or implied, except by separate agreement. my ($minimum_history_size) = 300; my ($maximum_history_size) = 600; my ($history_line_count) = 0; open HISTORY, "history" or die "No history file found"; while () { ++$history_line_count; } if ($history_line_count <= $maximum_history_size) { exit 0; } seek HISTORY, 0, 0 or die "Could not rewind history file"; my ($lines_to_trim) = $history_line_count - $minimum_history_size; my ($history_trim_suffix) = 1; while (-e "history_trim.$history_trim_suffix") { ++$history_trim_suffix; } open HISTORY_TRIM, ">history_trim.$history_trim_suffix" or die "Could not open file to write old history to"; open NEW_HISTORY, ">history.new" or die "Could not open history.new file"; $history_line_count = 0; while () { ++$history_line_count; if ($history_line_count <= $lines_to_trim) { print HISTORY_TRIM; } else { print NEW_HISTORY; } } close HISTORY, HISTORY_TRIM, NEW_HISTORY; rename("history.new", "history"); exit 0;