From 140a351fc535235ae5714122f0c98174cbdb19ce Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 19 Mar 2011 18:58:49 -0400 Subject: [PATCH] avoid version check before running version and upgrade commands There are two types of commands; those that access the repository and those that don't. Sorted. --- CmdLine.hs | 5 +++-- Command.hs | 13 ++++++++++--- Command/Add.hs | 2 +- Command/ConfigList.hs | 2 +- Command/Copy.hs | 2 +- Command/Describe.hs | 2 +- Command/Drop.hs | 2 +- Command/DropKey.hs | 2 +- Command/DropUnused.hs | 2 +- Command/Find.hs | 2 +- Command/Fix.hs | 2 +- Command/FromKey.hs | 2 +- Command/Fsck.hs | 2 +- Command/Get.hs | 2 +- Command/InAnnex.hs | 2 +- Command/Init.hs | 2 +- Command/Lock.hs | 2 +- Command/Map.hs | 2 +- Command/Migrate.hs | 2 +- Command/Move.hs | 2 +- Command/PreCommit.hs | 2 +- Command/RecvKey.hs | 2 +- Command/Semitrust.hs | 2 +- Command/SendKey.hs | 2 +- Command/SetKey.hs | 2 +- Command/Trust.hs | 2 +- Command/Unannex.hs | 2 +- Command/Uninit.hs | 2 +- Command/Unlock.hs | 4 ++-- Command/Untrust.hs | 2 +- Command/Unused.hs | 3 ++- Command/Version.hs | 2 +- Command/Whereis.hs | 2 +- 33 files changed, 46 insertions(+), 37 deletions(-) diff --git a/CmdLine.hs b/CmdLine.hs index 6b4fd0f368..de03d96ed4 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -45,7 +45,9 @@ parseCmd argv header cmds options = do [] -> error $ "unknown command" ++ usagemsg [command] -> do _ <- sequence flags - prepCmd command (drop 1 params) + when (cmdusesrepo command) $ + checkVersion + prepCommand command (drop 1 params) _ -> error "internal error: multiple matching commands" where getopt = case getOpt Permute options argv of @@ -93,7 +95,6 @@ tryRun' _ errnum [] = do startup :: Annex Bool startup = do prepUUID - checkVersion return True {- Cleanup actions. -} diff --git a/Command.hs b/Command.hs index 41ad884a93..1449d7eedf 100644 --- a/Command.hs +++ b/Command.hs @@ -61,13 +61,20 @@ data Command = Command { cmdname :: String, cmdparams :: String, cmdseek :: [CommandSeek], - cmddesc :: String + cmddesc :: String, + cmdusesrepo :: Bool } +repoCommand :: String -> String -> [CommandSeek] -> String -> Command +repoCommand n p s d = Command n p s d True + +standaloneCommand :: String -> String -> [CommandSeek] -> String -> Command +standaloneCommand n p s d = Command n p s d False + {- Prepares a list of actions to run to perform a command, based on - the parameters passed to it. -} -prepCmd :: Command -> [String] -> Annex [Annex Bool] -prepCmd Command { cmdseek = seek } params = do +prepCommand :: Command -> [String] -> Annex [Annex Bool] +prepCommand Command { cmdseek = seek } params = do lists <- mapM (\s -> s params) seek return $ map doCommand $ concat lists diff --git a/Command/Add.hs b/Command/Add.hs index a577203bf4..f6ccf0fb88 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -21,7 +21,7 @@ import Utility import Touch command :: [Command] -command = [Command "add" paramPath seek "add files to annex"] +command = [repoCommand "add" paramPath seek "add files to annex"] {- Add acts on both files not checked into git yet, and unlocked files. -} seek :: [CommandSeek] diff --git a/Command/ConfigList.hs b/Command/ConfigList.hs index b91c2a9160..476d73cfbb 100644 --- a/Command/ConfigList.hs +++ b/Command/ConfigList.hs @@ -14,7 +14,7 @@ import Command import UUID command :: [Command] -command = [Command "configlist" paramNothing seek +command = [standaloneCommand "configlist" paramNothing seek "outputs relevant git configuration"] seek :: [CommandSeek] diff --git a/Command/Copy.hs b/Command/Copy.hs index 93342e11bb..46d49dd058 100644 --- a/Command/Copy.hs +++ b/Command/Copy.hs @@ -11,7 +11,7 @@ import Command import qualified Command.Move command :: [Command] -command = [Command "copy" paramPath seek +command = [repoCommand "copy" paramPath seek "copy content of files to/from another repository"] -- A copy is just a move that does not delete the source file. diff --git a/Command/Describe.hs b/Command/Describe.hs index 643ca04718..32aef4f245 100644 --- a/Command/Describe.hs +++ b/Command/Describe.hs @@ -16,7 +16,7 @@ import Messages import qualified Command.Init command :: [Command] -command = [Command "describe" (paramPair paramRemote paramDesc) seek +command = [repoCommand "describe" (paramPair paramRemote paramDesc) seek "change description of a repository"] seek :: [CommandSeek] diff --git a/Command/Drop.hs b/Command/Drop.hs index fdc55969f0..52b724e62b 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -18,7 +18,7 @@ import Messages import Utility command :: [Command] -command = [Command "drop" paramPath seek +command = [repoCommand "drop" paramPath seek "indicate content of files not currently wanted"] seek :: [CommandSeek] diff --git a/Command/DropKey.hs b/Command/DropKey.hs index b3cc60961c..4c6f1ab2e1 100644 --- a/Command/DropKey.hs +++ b/Command/DropKey.hs @@ -15,7 +15,7 @@ import Content import Messages command :: [Command] -command = [Command "dropkey" (paramRepeating paramKey) seek +command = [repoCommand "dropkey" (paramRepeating paramKey) seek "drops annexed content for specified keys"] seek :: [CommandSeek] diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs index 8ed61ba65b..c6a28663ec 100644 --- a/Command/DropUnused.hs +++ b/Command/DropUnused.hs @@ -23,7 +23,7 @@ import Backend import Key command :: [Command] -command = [Command "dropunused" (paramRepeating paramNumber) seek +command = [repoCommand "dropunused" (paramRepeating paramNumber) seek "drop unused file content"] seek :: [CommandSeek] diff --git a/Command/Find.hs b/Command/Find.hs index 3ed15c1537..6a6ae29787 100644 --- a/Command/Find.hs +++ b/Command/Find.hs @@ -14,7 +14,7 @@ import Command import Content command :: [Command] -command = [Command "find" (paramOptional $ paramRepeating paramPath) seek +command = [repoCommand "find" (paramOptional $ paramRepeating paramPath) seek "lists available files"] seek :: [CommandSeek] diff --git a/Command/Fix.hs b/Command/Fix.hs index 0047548715..513e07a310 100644 --- a/Command/Fix.hs +++ b/Command/Fix.hs @@ -18,7 +18,7 @@ import Content import Messages command :: [Command] -command = [Command "fix" paramPath seek +command = [repoCommand "fix" paramPath seek "fix up symlinks to point to annexed content"] seek :: [CommandSeek] diff --git a/Command/FromKey.hs b/Command/FromKey.hs index 176d2cd54d..8c1a1028fe 100644 --- a/Command/FromKey.hs +++ b/Command/FromKey.hs @@ -21,7 +21,7 @@ import Messages import Key command :: [Command] -command = [Command "fromkey" paramPath seek +command = [repoCommand "fromkey" paramPath seek "adds a file using a specific key"] seek :: [CommandSeek] diff --git a/Command/Fsck.hs b/Command/Fsck.hs index 76d0e38b4b..216c87493b 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -20,7 +20,7 @@ import Content import LocationLog command :: [Command] -command = [Command "fsck" (paramOptional $ paramRepeating paramPath) seek +command = [repoCommand "fsck" (paramOptional $ paramRepeating paramPath) seek "check for problems"] seek :: [CommandSeek] diff --git a/Command/Get.hs b/Command/Get.hs index 2aa3c0c150..0463dccb05 100644 --- a/Command/Get.hs +++ b/Command/Get.hs @@ -14,7 +14,7 @@ import Content import Messages command :: [Command] -command = [Command "get" paramPath seek +command = [repoCommand "get" paramPath seek "make content of annexed files available"] seek :: [CommandSeek] diff --git a/Command/InAnnex.hs b/Command/InAnnex.hs index fa81fc9a4c..a7e2ecff60 100644 --- a/Command/InAnnex.hs +++ b/Command/InAnnex.hs @@ -14,7 +14,7 @@ import Command import Content command :: [Command] -command = [Command "inannex" (paramRepeating paramKey) seek +command = [repoCommand "inannex" (paramRepeating paramKey) seek "checks if keys are present in the annex"] seek :: [CommandSeek] diff --git a/Command/Init.hs b/Command/Init.hs index d9ea394a33..cca2e8faef 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -23,7 +23,7 @@ import Types import Utility command :: [Command] -command = [Command "init" paramDesc seek +command = [repoCommand "init" paramDesc seek "initialize git-annex with repository description"] seek :: [CommandSeek] diff --git a/Command/Lock.hs b/Command/Lock.hs index a3a39a9078..cdbc560194 100644 --- a/Command/Lock.hs +++ b/Command/Lock.hs @@ -17,7 +17,7 @@ import qualified GitRepo as Git import Utility command :: [Command] -command = [Command "lock" paramPath seek "undo unlock command"] +command = [repoCommand "lock" paramPath seek "undo unlock command"] seek :: [CommandSeek] seek = [withFilesUnlocked start] diff --git a/Command/Map.hs b/Command/Map.hs index 6c3e0b3df5..4ae947b15e 100644 --- a/Command/Map.hs +++ b/Command/Map.hs @@ -29,7 +29,7 @@ import qualified Dot data Link = Link Git.Repo Git.Repo command :: [Command] -command = [Command "map" paramNothing seek "generate map of repositories"] +command = [repoCommand "map" paramNothing seek "generate map of repositories"] seek :: [CommandSeek] seek = [withNothing start] diff --git a/Command/Migrate.hs b/Command/Migrate.hs index c0e80c5b47..584f6e34e1 100644 --- a/Command/Migrate.hs +++ b/Command/Migrate.hs @@ -21,7 +21,7 @@ import Messages import qualified Command.Add command :: [Command] -command = [Command "migrate" paramPath seek "switch data to different backend"] +command = [repoCommand "migrate" paramPath seek "switch data to different backend"] seek :: [CommandSeek] seek = [withBackendFilesInGit start] diff --git a/Command/Move.hs b/Command/Move.hs index 2d6c973fe0..8056e95dbe 100644 --- a/Command/Move.hs +++ b/Command/Move.hs @@ -22,7 +22,7 @@ import Messages import Utility command :: [Command] -command = [Command "move" paramPath seek +command = [repoCommand "move" paramPath seek "move content of files to/from another repository"] seek :: [CommandSeek] diff --git a/Command/PreCommit.hs b/Command/PreCommit.hs index 1465ebc615..727a637285 100644 --- a/Command/PreCommit.hs +++ b/Command/PreCommit.hs @@ -17,7 +17,7 @@ import qualified Command.Fix import Utility command :: [Command] -command = [Command "pre-commit" paramPath seek "run by git pre-commit hook"] +command = [repoCommand "pre-commit" paramPath seek "run by git pre-commit hook"] {- The pre-commit hook needs to fix symlinks to all files being committed. - And, it needs to inject unlocked files into the annex. -} diff --git a/Command/RecvKey.hs b/Command/RecvKey.hs index c7c37d1e31..126608f614 100644 --- a/Command/RecvKey.hs +++ b/Command/RecvKey.hs @@ -17,7 +17,7 @@ import Content import RsyncFile command :: [Command] -command = [Command "recvkey" paramKey seek +command = [repoCommand "recvkey" paramKey seek "runs rsync in server mode to receive content"] seek :: [CommandSeek] diff --git a/Command/Semitrust.hs b/Command/Semitrust.hs index 13c6847e17..351336b899 100644 --- a/Command/Semitrust.hs +++ b/Command/Semitrust.hs @@ -15,7 +15,7 @@ import Trust import Messages command :: [Command] -command = [Command "semitrust" (paramRepeating paramRemote) seek +command = [repoCommand "semitrust" (paramRepeating paramRemote) seek "return repository to default trust level"] seek :: [CommandSeek] diff --git a/Command/SendKey.hs b/Command/SendKey.hs index 56974bda96..871a530af7 100644 --- a/Command/SendKey.hs +++ b/Command/SendKey.hs @@ -18,7 +18,7 @@ import Content import RsyncFile command :: [Command] -command = [Command "sendkey" paramKey seek +command = [repoCommand "sendkey" paramKey seek "runs rsync in server mode to send content"] seek :: [CommandSeek] diff --git a/Command/SetKey.hs b/Command/SetKey.hs index fdda1c3bee..af46fe06e4 100644 --- a/Command/SetKey.hs +++ b/Command/SetKey.hs @@ -16,7 +16,7 @@ import Content import Messages command :: [Command] -command = [Command "setkey" (paramRepeating paramKey) seek +command = [repoCommand "setkey" (paramRepeating paramKey) seek "sets annexed content for a key using a temp file"] seek :: [CommandSeek] diff --git a/Command/Trust.hs b/Command/Trust.hs index ea661da2a6..f7dba56485 100644 --- a/Command/Trust.hs +++ b/Command/Trust.hs @@ -15,7 +15,7 @@ import UUID import Messages command :: [Command] -command = [Command "trust" (paramRepeating paramRemote) seek +command = [repoCommand "trust" (paramRepeating paramRemote) seek "trust a repository"] seek :: [CommandSeek] diff --git a/Command/Unannex.hs b/Command/Unannex.hs index 42dc1fb0ab..b0ce31ceed 100644 --- a/Command/Unannex.hs +++ b/Command/Unannex.hs @@ -22,7 +22,7 @@ import qualified GitRepo as Git import Messages command :: [Command] -command = [Command "unannex" paramPath seek "undo accidential add command"] +command = [repoCommand "unannex" paramPath seek "undo accidential add command"] seek :: [CommandSeek] seek = [withFilesInGit start] diff --git a/Command/Uninit.hs b/Command/Uninit.hs index e8ac1bbd5e..ee0cbde6b3 100644 --- a/Command/Uninit.hs +++ b/Command/Uninit.hs @@ -21,7 +21,7 @@ import qualified Command.Unannex import qualified Command.Init command :: [Command] -command = [Command "uninit" paramPath seek +command = [repoCommand "uninit" paramPath seek "de-initialize git-annex and clean out repository"] seek :: [CommandSeek] diff --git a/Command/Unlock.hs b/Command/Unlock.hs index bd1021cc3c..ac7b22ac72 100644 --- a/Command/Unlock.hs +++ b/Command/Unlock.hs @@ -22,8 +22,8 @@ import CopyFile command :: [Command] command = - [ Command "unlock" paramPath seek "unlock files for modification" - , Command "edit" paramPath seek "same as unlock" + [ repoCommand "unlock" paramPath seek "unlock files for modification" + , repoCommand "edit" paramPath seek "same as unlock" ] seek :: [CommandSeek] diff --git a/Command/Untrust.hs b/Command/Untrust.hs index fdf9a83dec..9c11efe465 100644 --- a/Command/Untrust.hs +++ b/Command/Untrust.hs @@ -15,7 +15,7 @@ import Trust import Messages command :: [Command] -command = [Command "untrust" (paramRepeating paramRemote) seek +command = [repoCommand "untrust" (paramRepeating paramRemote) seek "do not trust a repository"] seek :: [CommandSeek] diff --git a/Command/Unused.hs b/Command/Unused.hs index 52e483d870..a1c4ee03c9 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -25,7 +25,8 @@ import qualified GitRepo as Git import qualified Backend command :: [Command] -command = [Command "unused" paramNothing seek "look for unused file content"] +command = [repoCommand "unused" paramNothing seek + "look for unused file content"] seek :: [CommandSeek] seek = [withNothing start] diff --git a/Command/Version.hs b/Command/Version.hs index ac8fdd48c9..2b294c80be 100644 --- a/Command/Version.hs +++ b/Command/Version.hs @@ -15,7 +15,7 @@ import qualified SysConfig import Version command :: [Command] -command = [Command "version" paramNothing seek "show versions"] +command = [standaloneCommand "version" paramNothing seek "show version info"] seek :: [CommandSeek] seek = [withNothing start] diff --git a/Command/Whereis.hs b/Command/Whereis.hs index 5b0bcbbd26..599df44676 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -17,7 +17,7 @@ import UUID import Types command :: [Command] -command = [Command "whereis" (paramOptional $ paramRepeating paramPath) seek +command = [repoCommand "whereis" (paramOptional $ paramRepeating paramPath) seek "lists repositories that have file content"] seek :: [CommandSeek]