2 # This script finds all CVS/Entries files in the current directory and below
3 # and creates a local .cvsinclude file with non-inherited rules including each
4 # checked-in file. Then, use this option whenever using --cvs-exclude (-C):
8 # That ensures that all checked-in files/dirs are included in the transfer.
9 # (You could alternately put ": .cvsinclude" into an .rsync-filter file and
10 # use the -F option, which is easier to type.)
12 # The downside is that you need to remember to re-run cvs2includes whenever
13 # CVS gets an added or removed file. Maybe just run it before every copy.
17 INC_NAME = '.cvsinclude'
24 for root, dirs, files in os.walk('.'):
26 cvs_includes.add((root + '/' + INC_NAME)[2:])
27 if root.endswith('/CVS') and 'Entries' in files:
28 entries = root[2:] + '/Entries'
30 with open(entries) as fh:
32 if line.startswith(('/', 'D/')):
33 includes.append(line.split('/', 2)[1])
35 inc = root[2:-3] + INC_NAME
36 cvs_includes.discard(inc)
42 txt = ''.join(f"+ /{x}\n" for x in includes)
44 print("Unchanged", inc)
46 print("Updating", inc)
47 with open(inc, 'w') as fh:
51 for inc in sorted(cvs_includes):
52 print("Removing", inc)
56 if __name__ == '__main__':
57 parser = argparse.ArgumentParser(description=f"Transform CVS/Entries into {INC_NAME} files.", add_help=False)
58 parser.add_argument("--help", "-h", action="help", help="Output this help message and exit.")
59 parser.add_argument("dir", nargs='?', help="The top CVS dir. Defaults to the current directory.")
60 args = parser.parse_args()