1#!/usr/bin/perl
2#
3# This script finds all CVS/Entries files in the current directory and below
4# and creates a local .cvsinclude file with non-inherited rules including each
5# checked-in file.  Then, use this option whenever using --cvs-exclude (-C):
6#
7# 	-f ': .cvsinclude'
8#
9# That ensures that all checked-in files/dirs are included in the transfer.
10# (You could alternately put ": .cvsinclude" into an .rsync-filter file and
11# use the -F option, which is easier to type.)
12#
13# The downside is that you need to remember to re-run cvs2includes whenever
14# You add a new file to the project.
15use strict;
16
17open(FIND, 'find . -name CVS -type d |') or die $!;
18while (<FIND>) {
19    chomp;
20    s#^\./##;
21
22    my $entries = "$_/Entries";
23    s/CVS$/.cvsinclude/;
24    my $filter = $_;
25
26    open(ENTRIES, $entries) or die "Unable to open $entries: $!\n";
27    my @includes;
28    while (<ENTRIES>) {
29	push(@includes, $1) if m#/(.+?)/#;
30    }
31    close ENTRIES;
32    if (@includes) {
33	open(FILTER, ">$filter") or die "Unable to write $filter: $!\n";
34	print FILTER '+ /', join("\n+ /", @includes), "\n";
35	close FILTER;
36	print "Updated $filter\n";
37    } elsif (-f $filter) {
38	unlink($filter);
39	print "Removed $filter\n";
40    }
41}
42close FIND;
43