git-annex/Command/Version.hs
Joey Hess 9c4650358c
add KeyVariety type
Where before the "name" of a key and a backend was a string, this makes
it a concrete data type.

This is groundwork for allowing some varieties of keys to be disabled
in file2key, so git-annex won't use them at all.

Benchmarks ran in my big repo:

old git-annex info:

real	0m3.338s
user	0m3.124s
sys	0m0.244s

new git-annex info:

real	0m3.216s
user	0m3.024s
sys	0m0.220s

new git-annex find:

real	0m7.138s
user	0m6.924s
sys	0m0.252s

old git-annex find:

real	0m7.433s
user	0m7.240s
sys	0m0.232s

Surprising result; I'd have expected it to be slower since it now parses
all the key varieties. But, the parser is very simple and perhaps
sharing KeyVarieties uses less memory or something like that.

This commit was supported by the NSF-funded DataLad project.
2017-02-24 15:16:56 -04:00

76 lines
1.9 KiB
Haskell

{- git-annex command
-
- Copyright 2010 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Version where
import Command
import qualified Build.SysConfig as SysConfig
import Annex.Version
import BuildFlags
import Types.Key
import qualified Types.Backend as B
import qualified Types.Remote as R
import qualified Remote
import qualified Backend
import System.Info
cmd :: Command
cmd = dontCheck repoExists $ noCommit $
noRepo (seekNoRepo <$$> optParser) $
command "version" SectionQuery "show version info"
paramNothing (seek <$$> optParser)
data VersionOptions = VersionOptions
{ rawOption :: Bool
}
optParser :: CmdParamsDesc -> Parser VersionOptions
optParser _ = VersionOptions
<$> switch
( long "raw"
<> help "output only program version"
)
seek :: VersionOptions -> CommandSeek
seek o
| rawOption o = liftIO showRawVersion
| otherwise = showVersion
seekNoRepo :: VersionOptions -> IO ()
seekNoRepo o
| rawOption o = showRawVersion
| otherwise = showPackageVersion
showVersion :: Annex ()
showVersion = do
v <- getVersion
liftIO $ do
showPackageVersion
vinfo "local repository version" $ fromMaybe "unknown" v
vinfo "supported repository versions" $
unwords supportedVersions
vinfo "upgrade supported from repository versions" $
unwords upgradableVersions
vinfo "operating system" $
unwords [os, arch]
showPackageVersion :: IO ()
showPackageVersion = do
vinfo "git-annex version" SysConfig.packageversion
vinfo "build flags" $ unwords buildFlags
vinfo "key/value backends" $ unwords $
map (formatKeyVariety . B.backendVariety) Backend.list
vinfo "remote types" $ unwords $ map R.typename Remote.remoteTypes
showRawVersion :: IO ()
showRawVersion = do
putStr SysConfig.packageversion
hFlush stdout -- no newline, so flush
vinfo :: String -> String -> IO ()
vinfo k v = putStrLn $ k ++ ": " ++ v