+git-annex (8.20210715) UNRELEASED; urgency=medium
+
+ * whereused: New command, finds what files use a key, or where a key
+ was used historically.
+
+ -- Joey Hess <id@joeyh.name> Wed, 14 Jul 2021 14:26:36 -0400
+
git-annex (8.20210714) upstream; urgency=medium
* assistant: Avoid unncessary git repository repair in a situation where
import qualified Command.Find
import qualified Command.FindRef
import qualified Command.Whereis
+import qualified Command.WhereUsed
import qualified Command.List
import qualified Command.Log
import qualified Command.Merge
, Command.Find.cmd
, Command.FindRef.cmd
, Command.Whereis.cmd
+ , Command.WhereUsed.cmd
, Command.List.cmd
, Command.Log.cmd
, Command.Merge.cmd
--- /dev/null
+{- git-annex command
+ -
+ - Copyright 2021 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+module Command.WhereUsed where
+
+import Command
+import Git.FilePath
+import Annex.CatFile
+import Database.Keys
+
+cmd :: Command
+cmd = noCommit $ withGlobalOptions [annexedMatchingOptions] $
+ command "whereused" SectionQuery
+ "lists repositories that have file content"
+ paramNothing (seek <$$> optParser)
+
+data WhereUsedOptions = WhereUsedOptions
+ { keyOptions :: KeyOptions
+ , historicalOption :: Bool
+ }
+
+optParser :: CmdParamsDesc -> Parser WhereUsedOptions
+optParser _desc = WhereUsedOptions
+ <$> (parseUnusedKeysOption <|> parseSpecificKeyOption)
+ <*> switch
+ ( long "historical"
+ <> help "find historical uses"
+ )
+
+seek :: WhereUsedOptions -> CommandSeek
+seek o = withKeyOptions (Just (keyOptions o)) False dummyfileseeker
+ (commandAction . start o) dummyfilecommandseek (WorkTreeItems [])
+ where
+ dummyfileseeker = AnnexedFileSeeker
+ { startAction = \_ _ _ -> return Nothing
+ , checkContentPresent = Nothing
+ , usesLocationLog = False
+ }
+ dummyfilecommandseek = const noop
+
+start :: WhereUsedOptions -> (SeekInput, Key, ActionItem) -> CommandStart
+start o (_, key, _) = startingCustomOutput key $ do
+ fs <- filterM stillassociated
+ =<< mapM (fromRepo . fromTopFilePath)
+ =<< getAssociatedFiles key
+ liftIO $ forM_ fs $ display key . fromRawFilePath
+
+ when (historicalOption o && null fs) $
+ findHistorical key
+
+ next $ return True
+ where
+ -- Some associated files that are in the keys database may no
+ -- longer correspond to files in the repository.
+ stillassociated f = catKeyFile f >>= \case
+ Just k | k == key -> return True
+ _ -> return False
+
+display :: Key -> FilePath -> IO ()
+display key f = putStrLn (serializeKey key ++ " " ++ f)
+
+findHistorical :: Key -> Annex ()
+findHistorical key = do
+ error "TODO"
See [[git-annex-addunused]](1) for details.
-* `whereused`
-
- Finds what files use, or used a key.
-
* `fix [path ...]`
Fixes up symlinks that have become broken to again point to annexed content.
See [[git-annex-list]](1) for details.
+* `whereused`
+
+ Finds what files use, or used a key.
+
* `log [path ...]`
Displays the location log for the specified file or files,