forked from restic/restic
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter: ability to use negative patterns
This is quite similar to gitignore. If a pattern is suffixed by an exclamation mark and match a file that was previously matched by a regular pattern, the match is cancelled. Notably, this can be used with `--exclude-file` to cancel the exclusion of some files. Like for gitignore, once a directory is excluded, it is not possible to include files inside the directory. For example, a user wanting to only keep `*.c` in some directory should not use: ~/work !~/work/*.c But: ~/work/* !~/work/*.c I didn't write documentation or changelog entry. I would like to get feedback if this is the right approach for excluding/including files at will for backups. I use something like this as an exclude file to backup my home: $HOME/**/* !$HOME/Documents !$HOME/code !$HOME/.emacs.d !$HOME/games # [...] node_modules *~ *.o *.lo *.pyc # [...] $HOME/code/linux/* !$HOME/code/linux/.git # [...] There are some limitations for this change: - Patterns are not mixed accross methods: patterns from file are handled first and if a file is excluded with this method, it's not possible to reinclude it with `--exclude !something`. - Patterns starting with `!` are now interpreted as a negative pattern. I don't think anyone was relying on that. - The whole list of patterns is walked for each match. We may optimize later by exiting early if we know no pattern is starting with `!`. Fix restic#233
- Loading branch information
1 parent
d56329f
commit 86f53ab
Showing
4 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Enhancement: Add negative patterns for include/exclude | ||
|
||
If a pattern is suffixed by an exclamation mark and match a file that | ||
was previously matched by a regular pattern, the match is cancelled. | ||
Notably, this can be used with `--exclude-file` to cancel the | ||
exclusion of some files. | ||
|
||
It works similarly to `gitignore`, with the same limitation: once a | ||
directory is excluded, it is not possible to include files inside the | ||
directory. | ||
|
||
Example of use (as an exclude pattern for backup): | ||
|
||
$HOME/**/* | ||
!$HOME/Documents | ||
!$HOME/code | ||
!$HOME/.emacs.d | ||
!$HOME/games | ||
# [...] | ||
node_modules | ||
*~ | ||
*.o | ||
*.lo | ||
*.pyc | ||
# [...] | ||
$HOME/code/linux/* | ||
!$HOME/code/linux/.git | ||
# [...] | ||
|
||
https://github.com/restic/restic/issues/233 | ||
https://github.com/restic/restic/pull/2311 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters