onlyingroup
authorJoey Hess <joeyh@joeyh.name>
Mon, 31 Jul 2023 18:43:58 +0000 (14:43 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 31 Jul 2023 18:43:58 +0000 (14:43 -0400)
* Support "onlyingroup=" in preferred content expressions.
* Support --onlyingroup= matching option.

Sponsored-by: Jack Hill on Patreon
Annex/FileMatcher.hs
CHANGELOG
CmdLine/GitAnnex/Options.hs
Limit.hs
doc/git-annex-matching-options.mdwn
doc/git-annex-preferred-content.mdwn
doc/todo/comment_1_98d09316dc39619203e507f862716bab._comment [new file with mode: 0644]
doc/todo/onlyingroup_preferred_content_expression.mdwn

index ca3afa6a77d93df15bdb906ac898d58135927fce..6c049dfce438fcf051fbb9eafdf71bd460ee8b6e 100644 (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)]
index b04e4f2b5bfe229427c55c4cb77b24ef8d29b201..3845b4dd8ee2ffc30efb78b3c51d30c5f4ecf064 100644 (file)
--- 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 <id@joeyh.name>  Mon, 26 Jun 2023 13:10:40 -0400
 
index cce8917b5bd5dba9b595d3fec76809fc9b1ce823..92649fae346c278cd17ea150dec2aabfebd70ece 100644 (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
index bf1e85e69d2d4bc8e9fa2b515c4f49962f49c4b0..952b8885976df872df6280734943a73d3fee02cb 100644 (file)
--- 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
index 41de0d77b27c75ccba164f46d9bf28749d681775..83e07105e768530781768d2508995622c3611851 100644 (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`
 
index ea429228cf440d20746ad064e025ec7ff3912d8a..dd1cd5a506f44c135d907bf20abf40ed9094f9c7 100644 (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
diff --git a/doc/todo/comment_1_98d09316dc39619203e507f862716bab._comment b/doc/todo/comment_1_98d09316dc39619203e507f862716bab._comment
new file mode 100644 (file)
index 0000000..ed46d7b
--- /dev/null
@@ -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.
+"""]]
index ea628386a8f4cba6af9a71bd051235fef392285f..54abb4db0e9adab9960f561366f488021d3eafa8 100644 (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]]