From fa92383993abb8359613df5f24f36bfa72c8513e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 31 Jul 2023 14:43:58 -0400 Subject: [PATCH] onlyingroup * Support "onlyingroup=" in preferred content expressions. * Support --onlyingroup= matching option. Sponsored-by: Jack Hill on Patreon --- Annex/FileMatcher.hs | 1 + CHANGELOG | 2 ++ CmdLine/GitAnnex/Options.hs | 7 +++++- Limit.hs | 25 +++++++++++++++++++ doc/git-annex-matching-options.mdwn | 6 +++++ doc/git-annex-preferred-content.mdwn | 6 +++++ ..._98d09316dc39619203e507f862716bab._comment | 14 +++++++++++ ...yingroup_preferred_content_expression.mdwn | 2 ++ 8 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 doc/todo/comment_1_98d09316dc39619203e507f862716bab._comment diff --git a/Annex/FileMatcher.hs b/Annex/FileMatcher.hs index ca3afa6a77..6c049dfce4 100644 --- a/Annex/FileMatcher.hs +++ b/Annex/FileMatcher.hs @@ -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)] diff --git a/CHANGELOG b/CHANGELOG index b04e4f2b5b..3845b4dd8e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 Mon, 26 Jun 2023 13:10:40 -0400 diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index cce8917b5b..92649fae34 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -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 diff --git a/Limit.hs b/Limit.hs index bf1e85e69d..952b888597 100644 --- a/Limit.hs +++ b/Limit.hs @@ -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 diff --git a/doc/git-annex-matching-options.mdwn b/doc/git-annex-matching-options.mdwn index 41de0d77b2..83e07105e7 100644 --- a/doc/git-annex-matching-options.mdwn +++ b/doc/git-annex-matching-options.mdwn @@ -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` diff --git a/doc/git-annex-preferred-content.mdwn b/doc/git-annex-preferred-content.mdwn index ea429228cf..dd1cd5a506 100644 --- a/doc/git-annex-preferred-content.mdwn +++ b/doc/git-annex-preferred-content.mdwn @@ -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 diff --git a/doc/todo/comment_1_98d09316dc39619203e507f862716bab._comment b/doc/todo/comment_1_98d09316dc39619203e507f862716bab._comment new file mode 100644 index 0000000000..ed46d7ba19 --- /dev/null +++ b/doc/todo/comment_1_98d09316dc39619203e507f862716bab._comment @@ -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. +"""]] diff --git a/doc/todo/onlyingroup_preferred_content_expression.mdwn b/doc/todo/onlyingroup_preferred_content_expression.mdwn index ea628386a8..54abb4db0e 100644 --- a/doc/todo/onlyingroup_preferred_content_expression.mdwn +++ b/doc/todo/onlyingroup_preferred_content_expression.mdwn @@ -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]]