summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-10 18:05:37 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-10 18:05:37 -0400
commite5514e0cb0809848645814e8c1f67cd89cb16c4f (patch)
tree7041c952f9fa00fc60a40fa8e88fa1cd54818706
parentdce9c2e0804d2c94f46dcac8c9884766bb22dcc7 (diff)
update
-rw-r--r--Annex.hs1
-rw-r--r--Backend.hs14
-rw-r--r--BackendChecksum.hs3
-rw-r--r--BackendFile.hs3
-rw-r--r--BackendList.hs14
-rw-r--r--BackendUrl.hs3
-rw-r--r--CmdLine.hs41
-rw-r--r--GitRepo.hs13
-rw-r--r--LocationLog.hs1
-rw-r--r--Locations.hs3
-rw-r--r--Types.hs24
-rw-r--r--git-annex.hs17
12 files changed, 101 insertions, 36 deletions
diff --git a/Annex.hs b/Annex.hs
index f23358bf6..bddff1e13 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -8,6 +8,7 @@ import System.Directory
import GitRepo
import Utility
import Locations
+import Types
import Backend
{- Annexes a file, storing it in a backend, and then moving it into
diff --git a/Backend.hs b/Backend.hs
index e01f12239..93ceee234 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -22,19 +22,7 @@ import System.Directory
import Locations
import GitRepo
import Utility
-
-type Key = String
-
-data Backend = Backend {
- -- name of this backend
- name :: String,
- -- converts a filename to a key
- getKey :: GitRepo -> FilePath -> IO (Maybe Key),
- -- stores a file's contents to a key
- storeFileKey :: GitRepo -> FilePath -> Key -> IO (Bool),
- -- retrieves a key's contents to a file
- retrieveKeyFile :: IO Key -> FilePath -> IO (Bool)
-}
+import Types
instance Show Backend where
show backend = "Backend { name =\"" ++ (name backend) ++ "\" }"
diff --git a/BackendChecksum.hs b/BackendChecksum.hs
index 7b8d2c281..18ff0cb57 100644
--- a/BackendChecksum.hs
+++ b/BackendChecksum.hs
@@ -3,8 +3,7 @@
module BackendChecksum (backend) where
-import Backend
-import GitRepo
+import Types
import qualified BackendFile
import Data.Digest.Pure.SHA
diff --git a/BackendFile.hs b/BackendFile.hs
index 92f708696..deb4bce7e 100644
--- a/BackendFile.hs
+++ b/BackendFile.hs
@@ -3,8 +3,7 @@
module BackendFile (backend) where
-import Backend
-import GitRepo
+import Types
backend = Backend {
name = "file",
diff --git a/BackendList.hs b/BackendList.hs
new file mode 100644
index 000000000..c744949b6
--- /dev/null
+++ b/BackendList.hs
@@ -0,0 +1,14 @@
+{- git-annex backend list
+ - -}
+
+module BackendList where
+
+-- When adding a new backend, import it here and add it to the list.
+import qualified BackendFile
+import qualified BackendChecksum
+import qualified BackendUrl
+supportedBackends =
+ [ BackendFile.backend
+ , BackendChecksum.backend
+ , BackendUrl.backend
+ ]
diff --git a/BackendUrl.hs b/BackendUrl.hs
index 1aa5224b5..2bc34434b 100644
--- a/BackendUrl.hs
+++ b/BackendUrl.hs
@@ -3,8 +3,7 @@
module BackendUrl (backend) where
-import Backend
-import GitRepo
+import Types
backend = Backend {
name = "url",
diff --git a/CmdLine.hs b/CmdLine.hs
new file mode 100644
index 000000000..79bd55cd9
--- /dev/null
+++ b/CmdLine.hs
@@ -0,0 +1,41 @@
+{- git-annex command line
+ -
+ - TODO: This is very rough and stupid; I would like to use
+ - System.Console.CmdArgs.Implicit but it is not yet packaged in Debian.
+ -}
+
+module CmdLine where
+
+import System.Console.GetOpt
+import Types
+import Annex
+
+data Flag = Add FilePath | Push String | Pull String |
+ Want FilePath | Get (Maybe FilePath) | Drop FilePath
+ deriving Show
+
+options :: [OptDescr Flag]
+options =
+ [ Option ['a'] ["add"] (ReqArg Add "FILE") "add file to annex"
+ , Option ['p'] ["push"] (ReqArg Push "REPO") "push annex to repo"
+ , Option ['P'] ["pull"] (ReqArg Pull "REPO") "pull annex from repo"
+ , Option ['w'] ["want"] (ReqArg Want "FILE") "request file contents"
+ , Option ['g'] ["get"] (OptArg Get "FILE") "transfer file contents"
+ , Option ['d'] ["drop"] (ReqArg Drop "FILE") "indicate file content not needed"
+ ]
+
+argvToFlags argv = do
+ case getOpt Permute options argv of
+ -- no options? add listed files
+ ([],p,[] ) -> return $ map (\f -> Add f) p
+ -- all options parsed, return flags
+ (o,[],[] ) -> return o
+ -- error case
+ (_,n,errs) -> ioError (userError (concat errs ++ usageInfo header options))
+ where header = "Usage: git-annex [option] file"
+
+dispatch :: Flag -> [Backend] -> GitRepo -> IO ()
+dispatch flag backends repo = do
+ case (flag) of
+ Add f -> annexFile backends repo f
+ _ -> error "not implemented"
diff --git a/GitRepo.hs b/GitRepo.hs
index fda83f7d8..a0909d5ec 100644
--- a/GitRepo.hs
+++ b/GitRepo.hs
@@ -7,17 +7,18 @@ import System.Directory
import System.Path
import Data.String.Utils
import Utility
-
-data GitRepo = GitRepo {
- top :: FilePath,
- remotes :: [GitRepo]
-} deriving (Eq, Show, Read)
+import Types
+import BackendList
{- GitRepo constructor -}
gitRepo :: FilePath -> IO GitRepo
gitRepo dir = do
-- TOOD query repo for configuration settings; other repositories; etc
- return GitRepo { top = dir, remotes = [] }
+ return GitRepo {
+ top = dir,
+ remotes = [],
+ backends = supportedBackends
+ }
{- Path to a repository's gitattributes file. -}
gitAttributes :: GitRepo -> IO String
diff --git a/LocationLog.hs b/LocationLog.hs
index 73e9f1c6d..a5e9a2679 100644
--- a/LocationLog.hs
+++ b/LocationLog.hs
@@ -26,6 +26,7 @@ import Data.Char
import GitRepo
import Utility
import Locations
+import Types
data LogStatus = FilePresent | FileMissing | Undefined
deriving (Eq)
diff --git a/Locations.hs b/Locations.hs
index 7273797ef..50f94a727 100644
--- a/Locations.hs
+++ b/Locations.hs
@@ -3,10 +3,11 @@
module Locations where
+import Types
import GitRepo
{- An annexed file's content is stored somewhere under .git/annex/ -}
-annexDir :: GitRepo -> String -> IO FilePath
+annexDir :: GitRepo -> Key -> IO FilePath
annexDir repo key = do
dir <- gitDir repo
return $ dir ++ "/annex/" ++ key
diff --git a/Types.hs b/Types.hs
new file mode 100644
index 000000000..2308b6fde
--- /dev/null
+++ b/Types.hs
@@ -0,0 +1,24 @@
+{- git-annex data types
+ - -}
+
+module Types where
+
+type Key = String
+
+data Backend = Backend {
+ -- name of this backend
+ name :: String,
+ -- converts a filename to a key
+ getKey :: GitRepo -> FilePath -> IO (Maybe Key),
+ -- stores a file's contents to a key
+ storeFileKey :: GitRepo -> FilePath -> Key -> IO (Bool),
+ -- retrieves a key's contents to a file
+ retrieveKeyFile :: IO Key -> FilePath -> IO (Bool)
+}
+
+data GitRepo = GitRepo {
+ top :: FilePath,
+ remotes :: [GitRepo],
+ backends :: [Backend]
+}
+
diff --git a/git-annex.hs b/git-annex.hs
index f8c67b1fd..590a7c051 100644
--- a/git-annex.hs
+++ b/git-annex.hs
@@ -1,20 +1,17 @@
{- git-annex main program
- -}
-import LocationLog
+import System.Environment
import GitRepo
-import Backend
+import CmdLine
import Annex
-
--- When adding a new backend, import it here and add it to the backends list.
-import qualified BackendFile
-import qualified BackendChecksum
-import qualified BackendUrl
-backends = [BackendFile.backend, BackendChecksum.backend, BackendUrl.backend]
+import BackendList
main = do
+ args <- getArgs
+ flags <- argvToFlags args
+
repo <- currentRepo
gitPrep repo
- l <- readLog "demo.log"
- writeLog "demo2.log" $ compactLog l
+ mapM (\f -> dispatch f supportedBackends repo) flags