Skip to content

Commit

Permalink
Support for 'exclude_file' directive allows to e.g. load a content of…
Browse files Browse the repository at this point in the history
… .gitignore file instead of enumerating all exclusions in 'exclude' directive.
  • Loading branch information
dimikot committed May 28, 2015
1 parent 9a81e2b commit 30b66f8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions realsync
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ sub do_install {
# Pass.
}

if (!%CONFIG) {
push @config, {
"name" => "#exclude_file",
"value" => ".gitignore",
"comment" => "You may read exclusion list from e.g. a .gitignore file.",
};
}

if (!defined $CONFIG{nosound}) {
push @config, {
"name" => "nosound",
Expand Down Expand Up @@ -941,6 +949,8 @@ sub read_config {
next if !$k;
if ($k eq "exclude") {
push @{$config{exclude}}, $v;
} elsif ($k eq "exclude_file") {
push @{$config{exclude}}, read_exclude_file($v);
} elsif ($k eq "load") {
%config = (%config, read_config(File::Spec->rel2abs($v, dirname($file))));
} else {
Expand All @@ -954,6 +964,24 @@ sub read_config {
}


#
# Reads a content of .gitignore-like file.
#
sub read_exclude_file {
my ($file) = @_;
my @excludes = ();
open(local *F, $file) or die "Cannot open an exclude file $file: $!\n";
while (<F>) {
# Comments could be at the beginning of the line only,
# because "#" character is valid e.g. inside a file path.
s/^\s*#.*//sg;
s/^\s+|\s+$//sg;
push @excludes, $_ if length($_);
}
return @excludes;
}


#
# Converts filesystem wildcard into regular expression.
#
Expand Down

0 comments on commit 30b66f8

Please sign in to comment.