Git-annex is able to create trees that are a perspective of the "real" tree via adjustment and metadata-driven views.
It would be useful if git-annex was also able to create trees that are the same as the main branch but only include a subset of the files; decided based on internal and external metadata.
Use-cases:
- Only check out subtitles in a specific language to reduce clutter
- Only check out movies in one format
- Only check out images with a certain metadata tag
- Only check out files that are present
Some of these are already possible but would require manual metadata tagging or would result in a totally different tree. This can be confusing to both users and software.
UX examples:
$ ls Movies/
movie.mkv movie.iso movie.mp4 movie.en_US.ass movie.de_DE.ass
$ git annex filterview include=*.mkv
$ ls Movies/
movie.mkv
$ git annex filterview include=*.mp4 or include=*.enUS.ass
$ ls Movies/
movie.mp4 movie.en_US.ass
$ git annex filterview reset
$ ls Movies/
movie.mkv movie.iso movie.mp4 movie.en_US.ass movie.de_DE.ass
$ git annex get Movies
$ git annex filterview in=here
$ ls Movies/
movie.mkv movie.iso movie.mp4 movie.en_US.ass movie.de_DE.ass
$ git annex drop Movies/*.ass
$ ls Movies/
movie.mkv movie.iso movie.mp4
$ ls Photos/Cats/
very_cute.jpg awwwww.jpg :3.jpg
$ git annex filterview year=2022
$ ls Photos/Cats/
very_cute.jpg :3.jpg
Discussion points:
- Should filters be additive or replace the old one?
- Should it be possible to apply a filter to just a subtree?
Another useful feature that is tangentially related would be something like this:
$ git annex filterview root=Movies/
$ ls
movie.mkv movie.iso movie.mp4 movie.en_US.ass movie.de_DE.ass
Most of this can be done with either
git-annex adjust --hide-missingor views.The only thing that cannot is limiting files to those matching a glob, though views can limit files to the contents of directories.
Unfortunately, adjusted branches and views don't compose. There is a todo about that, ?unify adjust with view. I think that is what you're looking for, or very close.
Well, ajusted branches and views can be composed now.
Leaving this open for the glob patterns.
git-annex exportfilters the exported tree to the preferred content of the remote.That is not quite what's being asked for here, which is a new feature to generate a filtered tree. But clearly the code to create such a tree is all present in git-annex already.
In fact, an export to a special remote does write such a tree to a git ref. So a dummy special remote that didn't write any files would be one way to implement this. (Not a good way.)
I think the question is, what command would it make sense to put this feature in? And this seems like a good candiate:
git-annex adjust --wantedThat would adjust the tree to only contain files that are preferred content of the local repository.That seems broadly useful. Although similarly to --hide-missing, with some preferred content expressions (ones using
present), the adjusted branch sometimes needs to be updated when content availability changes, eg after agit-annex drop.The patch below implements that. Unfortunately, it fails to build due to several import cycles. I spent a while trying to resolve those and could not, so I think it would need HS boot files to get this to build.
I think the solution will involve depedency injection, so
ifWantedcan accesswantGetfrom a structure passed into that module from the caller. Maybe by converting it to a wrapper monad around Annex.