files-to-excludes 534 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/perl
  2. # This script takes an input of filenames and outputs a set of
  3. # include/exclude directives that can be used by rsync to copy
  4. # just the indicated files using an --exclude-from=FILE option.
  5. use strict;
  6. my %hash;
  7. while (<>) {
  8. chomp;
  9. s#^/+##;
  10. my $path = '/';
  11. while (m#([^/]+/)/*#g) {
  12. $path .= $1;
  13. print "+ $path\n" unless $hash{$path}++;
  14. }
  15. if (m#([^/]+)$#) {
  16. print "+ $path$1\n";
  17. } else {
  18. delete $hash{$path};
  19. }
  20. }
  21. foreach (sort keys %hash) {
  22. print "- $_*\n";
  23. }
  24. print "- /*\n";