onlyingroup

* Support "onlyingroup=" in preferred content expressions.
* Support --onlyingroup= matching option.

Sponsored-by: Jack Hill on Patreon
This commit is contained in:
Joey Hess 2023-07-31 14:43:58 -04:00
parent a17ece1428
commit fa92383993
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
8 changed files with 62 additions and 1 deletions

View file

@ -188,6 +188,7 @@ preferredContentKeyedTokens pcd =
, ValueToken "inbackend" (usev limitInBackend)
, ValueToken "metadata" (usev limitMetaData)
, ValueToken "inallgroup" (usev $ limitInAllGroup $ getGroupMap pcd)
, ValueToken "onlyingroup" (usev $ limitOnlyInGroup $ getGroupMap pcd)
] ++ commonKeyedTokens
preferredContentTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]

View file

@ -28,6 +28,8 @@ git-annex (10.20230627) UNRELEASED; urgency=medium
access.
* directory, gcrypt: Remove empty hash directories when dropping content.
* dropunused: Support --jobs
* Support "onlyingroup=" in preferred content expressions.
* Support --onlyingroup= matching option.
-- Joey Hess <id@joeyh.name> Mon, 26 Jun 2023 13:10:40 -0400

View file

@ -309,7 +309,12 @@ keyMatchingOptions' =
)
, annexOption (setAnnexState . Limit.addInAllGroup) $ strOption
( long "inallgroup" <> metavar paramGroup
<> help "match files present in all remotes in a group"
<> help "match files present in all repositories in a group"
<> hidden
)
, annexOption (setAnnexState . Limit.addOnlyInGroup) $ strOption
( long "onlyingroup" <> metavar paramGroup
<> help "match files that are only present in repositories in the group"
<> hidden
)
, annexOption (setAnnexState . Limit.addMetaData) $ strOption

View file

@ -509,6 +509,31 @@ limitInAllGroup getgroupmap groupname = Right $ MatchFiles
present <- S.fromList <$> Remote.keyLocations key
return $ S.null $ want `S.difference` present
{- Skip files that are only present in repositories that are not in the
- group. -}
addOnlyInGroup :: String -> Annex ()
addOnlyInGroup groupname = addLimit $ limitOnlyInGroup groupMap groupname
limitOnlyInGroup :: Annex GroupMap -> MkLimit Annex
limitOnlyInGroup getgroupmap groupname = Right $ MatchFiles
{ matchAction = \notpresent mi -> do
m <- getgroupmap
let want = fromMaybe S.empty $ M.lookup (toGroup groupname) $ uuidsByGroup m
if S.null want
then return False
else checkKey (check notpresent want) mi
, matchNeedsFileName = False
, matchNeedsFileContent = False
, matchNeedsKey = True
, matchNeedsLocationLog = True
, matchDesc = "inallgroup" =? groupname
}
where
check notpresent want key = do
locs <- S.fromList <$> Remote.keyLocations key
let present = locs `S.difference` notpresent
return $ not $ S.null $ present `S.intersection` want
{- Adds a limit to skip files not using a specified key-value backend. -}
addInBackend :: String -> Annex ()
addInBackend = addLimit . limitInBackend

View file

@ -127,6 +127,12 @@ in either of two repositories.
Matches only when git-annex believes content is present in
all repositories in the specified group.
* `--onlyingroup=groupname`
Matches only when git-annex believes content is present in at least one
repository that is in the specified group, and is not present in any
repositories that are not in the specified group.
* `--smallerthan=size`
* `--largerthan=size`

View file

@ -123,6 +123,12 @@ elsewhere to allow removing it).
Matches only files that git-annex believes are present in all repositories
in the specified group.
* `onlyingroup=groupname`
Matches files that git-annex believes are present in at least one
repository that is in the specified group, and are not present in any
repositories that are not in the specified group.
* `smallerthan=size` / `largerthan=size`
Matches only files whose content is smaller than, or larger than the

View file

@ -0,0 +1,14 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2023-07-31T18:41:03Z"
content="""
Matches files that git-annex believes are present in at least one
repository that is in the specified group, and are not present in any
repositories that are not in the specified group.
That's a pretty simple description and it allows matching when a repository
is in the specified group but is also in some other groups.
So that makes me happy with onlyingroup and I implemented it.
"""]]

View file

@ -20,3 +20,5 @@ Maybe you see an easier way, but this is what I came up with. I think an `onlyin
Cheers,
Yann
> [[done]] --[[Joey]]