findcomputed: New command, displays information about computed files.
authorJoey Hess <joeyh@joeyh.name>
Tue, 18 Mar 2025 16:55:48 +0000 (12:55 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 18 Mar 2025 16:55:48 +0000 (12:55 -0400)
CHANGELOG
CmdLine/GitAnnex.hs
Command/FindComputed.hs [new file with mode: 0644]
Remote/List/Util.hs
doc/git-annex-addcomputed.mdwn
doc/git-annex-findcomputed.mdwn [new file with mode: 0644]
doc/git-annex-recompute.mdwn
doc/git-annex.mdwn
doc/todo/compute_special_remote_remaining_todos.mdwn
git-annex.cabal

index 83df038ec390a530ec90af4bdcfd064460c3b3df..51298af244518be73e11bae5555c4f47630d50ba 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@ git-annex (10.20250116) UNRELEASED; urgency=medium
   * addcomputed: New command, adds a file that is generated by a compute
     special remote.
   * recompute: New command, recomputes computed files.
+  * findcomputed: New command, displays information about computed files.
   * Support help.autocorrect settings "prompt", "never", and "immediate".
   * Allow setting remote.foo.annex-tracking-branch to a branch name
     that contains "/", as long as it's not a remote tracking branch.
index 8dc64f8b7b093e4fbb1c789f22a1f3466f381a3a..503227887359986fcab9363cbb9185b5b4541d2c 100644 (file)
@@ -135,6 +135,7 @@ import qualified Command.MaxSize
 import qualified Command.Sim
 import qualified Command.AddComputed
 import qualified Command.Recompute
+import qualified Command.FindComputed
 import qualified Command.Version
 import qualified Command.RemoteDaemon
 #ifdef WITH_ASSISTANT
@@ -269,6 +270,7 @@ cmds testoptparser testrunner mkbenchmarkgenerator = map addGitAnnexCommonOption
        , Command.Sim.cmd
        , Command.AddComputed.cmd
        , Command.Recompute.cmd
+       , Command.FindComputed.cmd
        , Command.Version.cmd
        , Command.RemoteDaemon.cmd
 #ifdef WITH_ASSISTANT
diff --git a/Command/FindComputed.hs b/Command/FindComputed.hs
new file mode 100644 (file)
index 0000000..d9064b2
--- /dev/null
@@ -0,0 +1,93 @@
+{- git-annex command
+ -
+ - Copyright 2025 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+{-# LANGUAGE OverloadedStrings, TupleSections #-}
+
+module Command.FindComputed where
+
+import Command
+import Git.FilePath
+import qualified Utility.Format
+import Utility.Terminal
+import Command.Find (showFormatted, formatVars)
+import Remote.Compute (isComputeRemote, getComputeState, ComputeState(..))
+import qualified Remote
+import qualified Types.Remote as Remote
+
+cmd :: Command
+cmd = withAnnexOptions [annexedMatchingOptions] $ noCommit $ noMessages $
+       withAnnexOptions [jsonOptions] $
+               command "findcomputed" SectionQuery "lists computed files"
+                       paramPaths (seek <$$> optParser)
+
+data FindComputedOptions = FindComputedOptions
+       { findThese :: CmdParams
+       , formatOption :: Maybe Utility.Format.Format
+       , keyOptions :: Maybe KeyOptions
+       }
+
+optParser :: CmdParamsDesc -> Parser FindComputedOptions
+optParser desc = FindComputedOptions
+       <$> cmdParams desc
+       <*> optional parseFormatOption
+       <*> optional parseBranchKeysOption
+       
+parseFormatOption :: Parser Utility.Format.Format
+parseFormatOption = 
+       option (Utility.Format.gen <$> str)
+               ( long "format" <> metavar paramFormat
+               <> help "control format of output"
+               )
+
+seek :: FindComputedOptions -> CommandSeek
+seek o = do
+       unless (isJust (keyOptions o)) $
+               checkNotBareRepo
+       isterminal <- liftIO $ checkIsTerminal stdout
+       computeremotes <- filter isComputeRemote <$> Remote.remoteList
+       let seeker = AnnexedFileSeeker
+               { startAction = const (start o isterminal computeremotes)
+               , checkContentPresent = Nothing
+               , usesLocationLog = True
+               }
+       withKeyOptions (keyOptions o) False seeker
+               (commandAction . startKeys o isterminal computeremotes)
+               (withFilesInGitAnnex ww seeker)
+               =<< workTreeItems ww (findThese o)
+  where
+       ww = WarnUnmatchLsFiles "findcomputed"
+
+start :: FindComputedOptions -> IsTerminal -> [Remote] -> SeekInput -> OsPath -> Key -> CommandStart
+start o isterminal computeremotes _ file key = do
+       rs <- Remote.remotesWithUUID computeremotes
+               <$> Remote.keyLocations key
+       rcs <- catMaybes <$> forM rs get
+       if null rcs
+               then stop
+               else startingCustomOutput key $ do
+                       forM_ rcs $ \(r, c) -> do
+                               let computation = unwords (computeParams c)
+                               let unformatted = fromOsPath file 
+                                       <> " (" <> encodeBS (Remote.name r)
+                                       <> ") -- "
+                                       <> encodeBS computation
+                               let formatvars = 
+                                       [ ("remote", Remote.name r)
+                                       , ("computation", computation)
+                                       ] ++ formatVars key (AssociatedFile (Just file))
+                               showFormatted isterminal (formatOption o)
+                                       unformatted formatvars
+                       next $ return True
+  where
+       get r = fmap (r, )
+               <$> getComputeState (Remote.remoteStateHandle r) key
+
+startKeys :: FindComputedOptions -> IsTerminal -> [Remote] -> (SeekInput, Key, ActionItem) -> CommandStart
+startKeys o isterminal computeremotes (si, key, ActionItemBranchFilePath (BranchFilePath _ topf) _) =
+       start o isterminal computeremotes si (getTopFilePath topf) key
+startKeys _ _ _ _ = stop
+
index e022d231905e25202059f66c10117930c1c94459..c25119806739096e5c045bc0cc215811854b141a 100644 (file)
@@ -55,8 +55,8 @@ remoteLocations' (IncludeIgnored ii) locations trusted rs = do
 
        -- remotes that match uuids that have the key
        allremotes <- if not ii
-                       then filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . gitconfig) rs
-                       else return rs
+               then filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . gitconfig) rs
+               else return rs
        let validremotes = remotesWithUUID allremotes locations
 
        return (sortBy (comparing cost) validremotes, validtrustedlocations)
index 7b2ca0b86a807ff26b5d7eef72ee093bbf5f6617..0b59650268d61ac153ce4f311495ce1ae1379a1b 100644 (file)
@@ -99,6 +99,8 @@ the parameters provided to `git-annex addcomputed`.
 
 [[git-annex-recompute]](1)
 
+[[git-annex-findcomputed]](1)
+
 [[git-annex-initremote]](1)
 
 # AUTHOR
diff --git a/doc/git-annex-findcomputed.mdwn b/doc/git-annex-findcomputed.mdwn
new file mode 100644 (file)
index 0000000..a1c6cf1
--- /dev/null
@@ -0,0 +1,75 @@
+# NAME
+
+git-annex findcomputed - lists computed files
+
+# SYNOPSIS
+
+git annex findcomputed `[path ...]`
+
+# DESCRIPTION
+
+Outputs a list of files in the specified path that can be computed by
+enabled compute special remotes. With no path, lists files in the current
+directory and its subdirectories.
+
+Along with the name of each computed file, this displays the input that
+was provided to [[git-annex-addcomputed]](1).
+
+For example:
+
+    # git-annex findcomputed
+    foo.png (imageconvert) -- convert file.raw file.jpeg passes=10
+    bar.gz (compressor) -- compress bar --level=9
+
+# OPTIONS
+
+* matching options
+    
+  The [[git-annex-matching-options]](1)
+  can be used to specify files to list.
+
+* `--branch=ref`
+
+  List computed files in the specified branch or treeish.
+
+* `--format=value`
+
+  Use custom output formatting.
+
+  This option works the same as in [[git-annex-find]](1), with these
+  additional variables available for use in it: 
+  remote, computation
+
+  The default output format is the same as 
+  `--format='${file} (${remote}) -- ${computation}\\n'`,
+  except when outputting to a terminal, control characters will be escaped.
+
+* `--json`
+
+  Output the list of files in JSON format.
+
+  This is intended to be parsed by programs that use
+  git-annex. Each line of output is a JSON object.
+
+* `--json-error-messages`
+
+  Messages that would normally be output to standard error are included in
+  the JSON instead.
+
+# SEE ALSO
+
+[[git-annex]](1)
+
+[[git-annex-addcomputed]](1)
+
+[[git-annex-recompute]](1)
+
+[[git-annex-findcomputed]](1)
+
+[[git-annex-find]](1)
+
+# AUTHOR
+
+Joey Hess <id@joeyh.name>
+
+Warning: Automatically converted into a man page by mdwn2man. Edit with care.
index daf403471f4b9d53fd349aa95d442a2bd49b2447..a876d8d04f3c717285cda7a8be3339aacaa93570 100644 (file)
@@ -9,7 +9,7 @@ git-annex recompute [path ...]`
 # DESCRIPTION
 
 This updates computed files that were added with
-[[git-annex-addcomputed]](1). 
+[[git-annex-addcomputed]](1).
 
 By default, this only recomputes files whose input files have changed.
 The new contents of the input files are used to re-run the computation.
@@ -21,7 +21,7 @@ updated with the new content. The updated file is staged in git.
 
 * `--original`
 
-  Re-run the computation with the original input files.
+  Re-run the computation with the original input files content.
 
 * `--remote=name`
 
@@ -66,6 +66,8 @@ updated with the new content. The updated file is staged in git.
 
 [[git-annex-addcomputed]](1)
 
+[[git-annex-findcomputed]](1)
+
 # AUTHOR
 
 Joey Hess <id@joeyh.name>
index 5a39aa3bfa4297cb83bc8fa284abe0efef9a5214..dd1a862db49ca82aa5b0ee51d4be36b1e0649177 100644 (file)
@@ -198,6 +198,12 @@ content from the key-value store.
 
   See [[git-annex-recompute]](1) for details.
 
+* `findcomputed`
+
+  Lists computed files.
+
+  See [[git-annex-findcomputed]](1) for details.
+
 * `multicast`
 
   Multicast file distribution.
index 36a17f461f3a4162570f9621c6ab0cc1ac3ec2b6..c067051833f976072abf90172b05d248de9ad2a2 100644 (file)
@@ -15,18 +15,9 @@ compute special remote. --[[Joey]]
 * annex.diskreserve can also be violated if computing a file gets source
   files that are larger than the disk reserve. This could be checked.
 
-* would be nice to have a way to see what computations are used by a
-  compute remote for a file. Put it in `whereis` output? But it's not an
-  url. Maybe a separate command? That would also allow querying for eg,
-  what files are inputs for another file. 
+* Maybe add a file matching option, eg:
 
-  Or it could be exposed in the
-  Remote interface, and made into a file matching option:
-
-  git-annex find --inputof=foo
-
-  But that would require running expensive find over the whole tree,
-  and wouldn't work if the input file is no longer in the tree.
+  git-annex find --inputof=remote:file
 
 * allow git-annex enableremote with program= explicitly specified,
   without checking annex.security.allowed-compute-programs
index 2123b73663a52ed5e64ea1ce2d05d3763357a3ba..dccbd0e0405c6b545793f6e05b91652f72931ccc 100644 (file)
@@ -684,6 +684,7 @@ Executable git-annex
     Command.FilterBranch
     Command.FilterProcess
     Command.Find
+    Command.FindComputed
     Command.FindKeys
     Command.FindRef
     Command.Fix