summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-14 12:36:40 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-14 12:36:40 -0400
commit282d9853682f457cc6dc8b095b230bd892f0a5f3 (patch)
tree7a5af024e72e45ab85652adeea1853051b177449
parent0f12bd16d829432f7b1c2efbba386262ed36fc27 (diff)
default command
-rw-r--r--CmdLine.hs8
-rw-r--r--Commands.hs18
2 files changed, 18 insertions, 8 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
index 9737e0eb0..98971a733 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -14,7 +14,7 @@ import System.Console.GetOpt
import Types
import Commands
-data Mode = Add | Push | Pull | Want | Get | Drop | Unannex
+data Mode = Default | Add | Push | Pull | Want | Get | Drop | Unannex
deriving Show
options :: [OptDescr Mode]
@@ -30,8 +30,7 @@ options =
argvToMode argv = do
case getOpt Permute options argv of
- -- default mode is Add
- ([],files,[]) -> return (Add, files)
+ ([],files,[]) -> return (Default, files)
-- one mode is normal case
(m:[],files,[]) -> return (m, files)
-- multiple modes is an error
@@ -43,7 +42,8 @@ argvToMode argv = do
dispatch :: Mode -> FilePath -> Annex ()
dispatch mode item = do
case (mode) of
- Add -> annexCmd item
+ Default -> defaultCmd item
+ Add -> addCmd item
Push -> pushCmd item
Pull -> pullCmd item
Want -> wantCmd item
diff --git a/Commands.hs b/Commands.hs
index be61c7c64..b4f57d6fe 100644
--- a/Commands.hs
+++ b/Commands.hs
@@ -1,7 +1,8 @@
{- git-annex subcommands -}
module Commands (
- annexCmd,
+ defaultCmd,
+ addCmd,
unannexCmd,
getCmd,
wantCmd,
@@ -25,10 +26,19 @@ import UUID
import LocationLog
import Types
+{- Default mode is to annex a file if it is not already, and otherwise
+ - get its content. -}
+defaultCmd :: FilePath -> Annex ()
+defaultCmd file = do
+ r <- liftIO $ Backend.lookupFile file
+ case (r) of
+ Just v -> getCmd file
+ Nothing -> addCmd file
+
{- Annexes a file, storing it in a backend, and then moving it into
- the annex directory and setting up the symlink pointing to its content. -}
-annexCmd :: FilePath -> Annex ()
-annexCmd file = inBackend file err $ do
+addCmd :: FilePath -> Annex ()
+addCmd file = inBackend file err $ do
liftIO $ checkLegal file
stored <- Backend.storeFile file
g <- Annex.gitRepo
@@ -63,7 +73,7 @@ annexCmd file = inBackend file err $ do
subdirs = (length $ split "/" file) - 1
-{- Inverse of annexCmd. -}
+{- Inverse of addCmd. -}
unannexCmd :: FilePath -> Annex ()
unannexCmd file = notinBackend file err $ \(key, backend) -> do
Backend.dropFile backend key