filter: ability to use negative patterns#2311
Conversation
|
Looks good, although at present I don't think it handles this case: i.e. the current logic excludes This solution needs special handling of the I've worked some logic which appears to work and will add tomorrow. It needs to consider both exclude and include cases. |
|
Yes, you are right, this is not handled correctly. It should be: Not very user-friendly. But on par with git (though for git, this kind of case is not very common). |
|
Understood, thanks, although I think highly preferable to handle this as per the two-line formulation. Thoughts? Also, this PR does not currently handle restore presently (same filter code used in e.g. this should restore |
|
For this example, yes. But what about: Should we include As for restore, I think you want |
|
Regarding general logic, I think you are right. The additional terms are better than the requirement to walk additional subtrees. Thanks. In regards to the restore, I'm presuming you mean I believe the issue is that the So becomes This works for my restore case. Thoughts? |
|
I also suggest another expansion of the filter tests is warranted - a few extra cases and capturing the Thoughts? |
|
You said But you are right, there is something different about restore. Just using a negative pattern is enough to make it fail. We should add tests for the this as there is currently none. |
Argh! Sorry - the test restore (that works with the change I suggest) is to exclude 'a' through 'm' and include 'n' through 'z'. |
Yes. The tests I suggest in my commit danielsharvey@7cb1815 and danielsharvey@6a4938a that capture this and the other checks we've been discussing are: But, I still had not properly considered the |
ec44001 to
5473bb5
Compare
|
Hey! Sorry for the late answer, I was a bit busy lately. So you were right. I have added a commit with tests for |
|
Thanks, looks good to me. |
5473bb5 to
86f53ab
Compare
|
Thanks @danielsharvey for the review! I have added the documentation and the changelog entry. The PR should be ready for a formal review. |
Codecov Report
@@ Coverage Diff @@
## master #2311 +/- ##
==========================================
- Coverage 51.09% 46.84% -4.26%
==========================================
Files 178 178
Lines 14546 14550 +4
==========================================
- Hits 7433 6816 -617
- Misses 6042 6720 +678
+ Partials 1071 1014 -57
Continue to review full report at Codecov.
|
|
@fd0 Is there any process that we should follow to progress PRs like this one? I have been using this for some time and would love to see it merged. Thanks! |
|
Following up on the comments by @MichaelEischer would be the process, but in the end it boils down to the core developers' time constraints. There are many other changes that are being worked on, patience is needed :) |
86f53ab to
45a979f
Compare
|
I have rebased the commit and use the second approach, suggested by @MichaelEischer |
|
Thanks @rawtaz, I appreciate the challenge of volunteer efforts. And apologies, I had missed that @MichaelEischer's comments had not been fully responded to (now done). |
|
To anyone else; Has anyone else tested this in production? Please let us know :) |
|
I'm not "anyone else", but just to add clarity to my use cases (in regular use by me):
Attachment: restic-excludes-negative |
|
If there is still hope to get this merged, I can try another rebase... |
fd0
left a comment
There was a problem hiding this comment.
I'm sorry for the long delay, I've talked with @MichaelEischer and we're inclined to include this PR. Can you please rebase again?
I've not looked at the code too deeply, but I've seen two mistakes in the documentation and changelog.
|
I did have a look, but there are too many changes to easily rebase. If anyone wants to give it a try, they are welcome to take over this PR. |
|
I understand, thanks for your work! |
45a979f to
689979d
Compare
MichaelEischer
left a comment
There was a problem hiding this comment.
@fd0 I've rebased the PR. The check whether a pattern is negated now occurs once while preparing the pattern. That required some refactoring, in separate commits, to change the Pattern type from a slice to a struct.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@MichaelEischer @fd0 Thanks for all the work. Just checking in - any assistance required to finalise this? |
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
689979d to
53656f0
Compare
fd0
left a comment
There was a problem hiding this comment.
Thank you very much for your patience, I'm approving this PR!
|
Does the new exclamation mark functionality work for inclusions using |
|
No, the negative patterns are only available for exclusions. A negative pattern in files-from would actually be an exclude, so it should just work to specify it as such? |
|
@MichaelEischer Are we able to represent any sort of ordering with this approach? Meaning, can I specify the following?
If I remember correctly, the exclusion of the parent directory will override any inclusion of the children directories. |
|
@cowwoc You absolutely can. My backup selectively backs up using this mechanism: restic <...> --exclude-file ~/backup/readme/restic-excludes-negative ~/My excludes file looks like this: Note the pattern:
|
This is quite similar to gitignore. If a pattern is prefixed 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-fileto 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
*.cin some directory should not use:But:
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:
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 negativepattern. 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 #233
Checklist
changelog/unreleased/that describes the changes for our users (template here)gofmton the code in all commits