new matching options --want-get-by and --want-drop-by
authorJoey Hess <joeyh@joeyh.name>
Thu, 28 Jul 2022 17:26:03 +0000 (13:26 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 28 Jul 2022 17:26:03 +0000 (13:26 -0400)
Sponsored-by: Graham Spencer on Patreon
Annex/Wanted.hs
Assistant/Threads/TransferScanner.hs
Assistant/TransferQueue.hs
Assistant/TransferSlots.hs
CHANGELOG
CmdLine/GitAnnex/Options.hs
Command/Copy.hs
Command/Sync.hs
Limit/Wanted.hs
doc/git-annex-matching-options.mdwn
doc/todo/wishlist__58___--dry-run_option_for_all_commands.mdwn

index cb2a8e3401a5a35ceac66eeeefaf5f94502f660c..87fdbdae498bc264cb1a66b69e2e366c8e1628b8 100644 (file)
@@ -22,8 +22,8 @@ wantGet :: Bool -> Maybe Key -> AssociatedFile -> Annex Bool
 wantGet d key file = isPreferredContent Nothing S.empty key file d
 
 {- Check if a file is preferred content for a repository. -}
-wantSend :: Bool -> Maybe Key -> AssociatedFile -> UUID -> Annex Bool
-wantSend d key file to = isPreferredContent (Just to) S.empty key file d
+wantGetBy :: Bool -> Maybe Key -> AssociatedFile -> UUID -> Annex Bool
+wantGetBy d key file to = isPreferredContent (Just to) S.empty key file d
 
 {- Check if a file is not preferred or required content, and can be
  - dropped. When a UUID is provided, checks for that repository.
index b771e9f8e964419703c005a19179a642a554e7d2..970516a38026ba99dc70264ffe587984c9bf4f8d 100644 (file)
@@ -171,7 +171,7 @@ expensiveScan urlrenderer rs = batch <~> do
                        "expensive scan found too many copies of object"
                        present key af (SeekInput []) [] callCommandAction
                ts <- if present
-                       then liftAnnex . filterM (wantSend True (Just key) af . Remote.uuid . fst)
+                       then liftAnnex . filterM (wantGetBy True (Just key) af . Remote.uuid . fst)
                                =<< use syncDataRemotes (genTransfer Upload False)
                        else ifM (liftAnnex $ wantGet True (Just key) af)
                                ( use downloadRemotes (genTransfer Download True) , return [] )
index c852615ed17264a29f9714b8790ebdabcf740e71..ec5f0ab318d73bae7fedf3a333adab24fe730134 100644 (file)
@@ -88,7 +88,7 @@ queueTransfersMatching matching reason schedule k f direction
                 - already have it. -}
                | otherwise = do
                        s <- locs
-                       filterM (wantSend True (Just k) f . Remote.uuid) $
+                       filterM (wantGetBy True (Just k) f . Remote.uuid) $
                                filter (\r -> not (inset s r || Remote.readonly r))
                                        (syncDataRemotes st)
          where
index f49a995ac4640ba7f0b5c5f4db2d7aef7b624f7a..0ea91ab00eb325542f202a7f68e03cc4ac325bdc 100644 (file)
@@ -212,7 +212,7 @@ shouldTransfer t info
        | transferDirection t == Upload = case transferRemote info of
                Nothing -> return False
                Just r -> notinremote r
-                       <&&> wantSend True (Just key) file (Remote.uuid r)
+                       <&&> wantGetBy True (Just key) file (Remote.uuid r)
        | otherwise = return False
   where
        key = transferKey t
index f336a3c5fcfe35b89a1f8e5aff3b122031af264c..13a00e5c326202bb5c0fa8565b3db09289bf37f1 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ git-annex (10.20220725) UNRELEASED; urgency=medium
   * Avoid starting an unncessary number of git hash-object processes when 
     concurrency is enabled.
   * stack.yaml: Updated to lts-19.16
+  * Added new matching options --want-get-by and --want-drop-by.
 
  -- Joey Hess <id@joeyh.name>  Mon, 25 Jul 2022 15:35:45 -0400
 
index 96d0b1872d5715d259f70a085beaf05deae4fd4a..48d7a3daf47cd9b23feb13290541e9ea8ca2e6a9 100644 (file)
@@ -288,12 +288,23 @@ keyMatchingOptions' =
                )
        , annexFlag (setAnnexState Limit.Wanted.addWantGet)
                ( long "want-get"
-               <> help "match files the repository wants to get"
+               <> help "match files the local repository wants to get"
                <> hidden
                )
+       , annexOption (setAnnexState . Limit.Wanted.addWantGetBy) $ strOption
+               ( long "want-get-by" <> metavar paramRemote
+               <> help "match files the specified repository wants to get"
+               <> hidden
+               <> completeRemotes
+               )
        , annexFlag (setAnnexState Limit.Wanted.addWantDrop)
                ( long "want-drop"
-               <> help "match files the repository wants to drop"
+               <> help "match files the local repository wants to drop"
+               <> hidden
+               )
+       , annexOption (setAnnexState . Limit.Wanted.addWantDropBy) $ strOption
+               ( long "want-drop-by" <> metavar paramRemote
+               <> help "match files the specified repository wants to drop"
                <> hidden
                )
        , annexOption (setAnnexState . Limit.addAccessedWithin) $
index bc386894d4c66e6e9549cca62799284e67f309b8..267fa71d3d175d21daaf6be4f268a878b2533837 100644 (file)
@@ -82,5 +82,5 @@ start o si file key = stopUnless shouldCopy $
                Right (FromRemote _) -> checkwantget
                Left ToHere -> checkwantget
                        
-       checkwantsend = wantSend False (Just key) (AssociatedFile (Just file))
+       checkwantsend = wantGetBy False (Just key) (AssociatedFile (Just file))
        checkwantget = wantGet False (Just key) (AssociatedFile (Just file))
index bad311ed3a1abbe89b2c325ea6d7989c69b61696..167ea08b7abd9801eb7033d0305c0d6f4afca3eb 100644 (file)
@@ -855,7 +855,7 @@ syncFile ebloom rs af k = do
        wantput r
                | Remote.readonly r || remoteAnnexReadOnly (Remote.gitconfig r) = return False
                | isThirdPartyPopulated r = return False
-               | otherwise = wantSend True (Just k) af (Remote.uuid r)
+               | otherwise = wantGetBy True (Just k) af (Remote.uuid r)
        handleput lack inhere
                | inhere = catMaybes <$>
                        ( forM lack $ \r ->
index 9188594b90e282bce91aa01c1f0816cb9f5af56e..7eb8df7ad4c5f8069c50a36480cf7ee658648be1 100644 (file)
@@ -12,14 +12,27 @@ import Annex.Wanted
 import Limit
 import Types.FileMatcher
 import Logs.PreferredContent
+import qualified Remote
 
 addWantGet :: Annex ()
 addWantGet = addPreferredContentLimit $
        checkWant $ wantGet False Nothing
 
+addWantGetBy :: String -> Annex ()
+addWantGetBy name = do
+       u <- Remote.nameToUUID name
+       addPreferredContentLimit $ checkWant $ \af ->
+               wantGetBy False Nothing af u
+
 addWantDrop :: Annex ()
-addWantDrop = addPreferredContentLimit $
-       checkWant $ \af -> wantDrop False Nothing Nothing af (Just [])
+addWantDrop = addPreferredContentLimit $ checkWant $ \af ->
+       wantDrop False Nothing Nothing af (Just [])
+
+addWantDropBy :: String -> Annex ()
+addWantDropBy name = do
+       u <- Remote.nameToUUID name
+       addPreferredContentLimit $ checkWant $ \af ->
+               wantDrop False (Just u) Nothing af (Just [])
 
 addPreferredContentLimit :: (MatchInfo -> Annex Bool) -> Annex ()
 addPreferredContentLimit a = do
index 93172165ca3e3938c6d5a3544d1dbc0737a8284c..199063a15418c61a9da2ccb5ce4bbb8086a5a9f4 100644 (file)
@@ -153,21 +153,43 @@ in either of two repositories.
 
 * `--want-get`
 
-  Matches only when the preferred content settings for the repository
+  Matches only when the preferred content settings for the local repository
   make it want to get content. Note that this will match even when
-  the content is already present, unless limited with e.g., `--not --in .`
+  the content is already present, unless limited with e.g., `--not --in=here`
 
 * `--want-drop`
 
-  Matches only when the preferred content settings for the repository
+  Matches only when the preferred content settings for the local repository
   make it want to drop content. Note that this will match even when
-  the content is not present, unless limited with e.g., `--in .`
+  the content is not present, unless limited with e.g., `--not --in=here`
 
   Things that this matches will not necessarily be dropped by
   `git-annex drop --auto`. This does not check that there are enough copies
   to drop. Also the same content may be used by a file that is not wanted
   to be dropped.
 
+* `--want-get-by=repository`
+
+  Matches only when the preferred content settings for the specified 
+  repository make it want to get content. Note that this will match even when
+  the content is already present in that repository, unless limited with e.g.,
+  `--not --in=repository`
+
+  The repository should be specified using the name of a configured remote,
+  or the UUID or description of a repository. `--want-get-by=here`
+  is the same as `--want-get`.
+
+* `--want-drop-by=repository`
+
+  Matches only when the preferred content settings for the specificed
+  repository make it want to drop content. Note that this will match
+  even when the content is not present, unless limited with e.g., 
+  `--not --in=repository`
+  The repository should be specified using the name of a configured remote,
+  or the UUID or description of a repository. `--want-drop-by=here`
+  is the same as `--want-drop`.
+
 * `--accessedwithin=interval`
 
   Matches when the content was accessed recently, within the specified time
index fbea1b6faf0cd2b624d88a4d87d87348f69d03e5..dd2a6263e5255b50b489759e5c5e4c646669d3e2 100644 (file)
@@ -1,3 +1,6 @@
 Could a --dry-run option be added to the git annex commands? Or, at least, to the most common ones like `git annex add`.
 
 Given that there is no undo command, it would be nice to have the ability to simulate what git annex will do.
+
+> [[wontfix|done]], see comments. Instead, options like --want-get and
+> --want-drop can be used to simulate things. --[[Joey]]