]> dgit.raspbian.org Git - git-annex.git/commitdiff
whereused implemented
authorJoey Hess <joeyh@joeyh.name>
Wed, 14 Jul 2021 18:25:52 +0000 (14:25 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 14 Jul 2021 18:27:21 +0000 (14:27 -0400)
except --historical

Sponsored-by: Jack Hill on Patreon
CHANGELOG
CmdLine/GitAnnex.hs
Command/WhereUsed.hs [new file with mode: 0644]
doc/git-annex-whereused.mdwn
doc/git-annex.mdwn
git-annex.cabal

index d822869bcfe8c91f3ac7bdfd3ef81348ea94eca7..00ec380f96b4a2de91d7ea03fed388c405765ab2 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+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
index fe400814839d403915749d3d08c5785c39d8eca9..807aa140838f0ad802358c28308c68f38cab1f10 100644 (file)
@@ -72,6 +72,7 @@ import qualified Command.FilterBranch
 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
@@ -207,6 +208,7 @@ cmds testoptparser testrunner mkbenchmarkgenerator = map addGitAnnexGlobalOption
        , Command.Find.cmd
        , Command.FindRef.cmd
        , Command.Whereis.cmd
+       , Command.WhereUsed.cmd
        , Command.List.cmd
        , Command.Log.cmd
        , Command.Merge.cmd
diff --git a/Command/WhereUsed.hs b/Command/WhereUsed.hs
new file mode 100644 (file)
index 0000000..4534d90
--- /dev/null
@@ -0,0 +1,68 @@
+{- 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"
index d142aae7fc8ab2808082f803b19c20e47fa98267..385720c5e14e29e0545354c8208ffa6fa27e6592 100644 (file)
@@ -4,7 +4,7 @@ git-annex whereused - find what files use, or used a key
 
 # SYNOPSIS
 
-git annex whereused `--key=K|--unused`
+git annex whereused `--key=keyname|--unused`
 
 # DESCRIPTION
 
index 82b692512061736bfe3c2944f08ed372877ca445..ca5d69fe3444d7dcc00d97732027e5bd679a5b8b 100644 (file)
@@ -373,10 +373,6 @@ content from the key-value store.
   
   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.
@@ -451,6 +447,10 @@ content from the key-value store.
   
   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,
index bf6df7557e5ea8c88a88c0dac270299b1f5eb4a0..6b5684ea533e70e7838966ac012401da671720c5 100644 (file)
@@ -144,6 +144,7 @@ Extra-Source-Files:
   doc/git-annex-watch.mdwn
   doc/git-annex-webapp.mdwn
   doc/git-annex-whereis.mdwn
+  doc/git-annex-whereused.mdwn
   doc/git-remote-tor-annex.mdwn
   doc/logo.svg
   doc/logo_16x16.png
@@ -830,6 +831,7 @@ Executable git-annex
     Command.View
     Command.Wanted
     Command.Whereis
+    Command.WhereUsed
     Common
     Config
     Config.Cost