git annex describe
This commit is contained in:
parent
81d628a8cd
commit
6d13ae10cf
5 changed files with 30 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
||||||
{- git-annex key/value storage backends
|
{- git-annex key-value storage backends
|
||||||
-
|
-
|
||||||
- git-annex uses a key/value abstraction layer to allow files contents to be
|
- git-annex uses a key-value abstraction layer to allow files contents to be
|
||||||
- stored in different ways. In theory, any key/value storage system could be
|
- stored in different ways. In theory, any key-value storage system could be
|
||||||
- used to store the file contents, and git-annex would then retrieve them
|
- used to store the file contents, and git-annex would then retrieve them
|
||||||
- as needed and put them in `.git/annex/`.
|
- as needed and put them in `.git/annex/`.
|
||||||
-
|
-
|
||||||
|
|
|
@ -58,7 +58,7 @@ copyKeyFile key file = do
|
||||||
else return ()
|
else return ()
|
||||||
trycopy remotes remotes
|
trycopy remotes remotes
|
||||||
where
|
where
|
||||||
trycopy full [] = error $ "unable to get: " ++ (keyFile key) ++ "\n" ++
|
trycopy full [] = error $ "unable to get file with key: " ++ (keyFile key) ++ "\n" ++
|
||||||
"To get that file, need access to one of these remotes: " ++
|
"To get that file, need access to one of these remotes: " ++
|
||||||
(Remotes.list full)
|
(Remotes.list full)
|
||||||
trycopy full (r:rs) = do
|
trycopy full (r:rs) = do
|
||||||
|
@ -79,7 +79,7 @@ copyKeyFile key file = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
uuids <- liftIO $ keyLocations g key
|
uuids <- liftIO $ keyLocations g key
|
||||||
ppuuids <- prettyPrintUUIDs uuids
|
ppuuids <- prettyPrintUUIDs uuids
|
||||||
error $ "no available git remotes have: " ++
|
error $ "no available git remotes have file with key: " ++
|
||||||
(keyFile key) ++
|
(keyFile key) ++
|
||||||
if (0 < length uuids)
|
if (0 < length uuids)
|
||||||
then "\nIt has been seen before in these repositories:\n" ++ ppuuids
|
then "\nIt has been seen before in these repositories:\n" ++ ppuuids
|
||||||
|
|
|
@ -49,7 +49,7 @@ backendName (Key (b,k)) = b
|
||||||
keyFrag :: Key -> KeyFrag
|
keyFrag :: Key -> KeyFrag
|
||||||
keyFrag (Key (b,k)) = k
|
keyFrag (Key (b,k)) = k
|
||||||
|
|
||||||
-- this structure represents a key/value backend
|
-- this structure represents a key-value backend
|
||||||
data Backend = Backend {
|
data Backend = Backend {
|
||||||
-- name of this backend
|
-- name of this backend
|
||||||
name :: String,
|
name :: String,
|
||||||
|
|
24
Commands.hs
24
Commands.hs
|
@ -23,7 +23,7 @@ import Core
|
||||||
import qualified Remotes
|
import qualified Remotes
|
||||||
import qualified BackendTypes
|
import qualified BackendTypes
|
||||||
|
|
||||||
data CmdWants = FilesInGit | FilesNotInGit | RepoName
|
data CmdWants = FilesInGit | FilesNotInGit | RepoName | SingleString
|
||||||
data Command = Command {
|
data Command = Command {
|
||||||
cmdname :: String,
|
cmdname :: String,
|
||||||
cmdaction :: (String -> Annex ()),
|
cmdaction :: (String -> Annex ()),
|
||||||
|
@ -34,10 +34,10 @@ cmds :: [Command]
|
||||||
cmds = [ (Command "add" addCmd FilesNotInGit)
|
cmds = [ (Command "add" addCmd FilesNotInGit)
|
||||||
, (Command "get" getCmd FilesInGit)
|
, (Command "get" getCmd FilesInGit)
|
||||||
, (Command "drop" dropCmd FilesInGit)
|
, (Command "drop" dropCmd FilesInGit)
|
||||||
, (Command "want" wantCmd FilesInGit)
|
|
||||||
, (Command "push" pushCmd RepoName)
|
, (Command "push" pushCmd RepoName)
|
||||||
, (Command "pull" pullCmd RepoName)
|
, (Command "pull" pullCmd RepoName)
|
||||||
, (Command "unannex" unannexCmd FilesInGit)
|
, (Command "unannex" unannexCmd FilesInGit)
|
||||||
|
, (Command "describe" describeCmd SingleString)
|
||||||
]
|
]
|
||||||
|
|
||||||
{- Finds the type of parameters a command wants, from among the passed
|
{- Finds the type of parameters a command wants, from among the passed
|
||||||
|
@ -49,6 +49,8 @@ findWanted FilesNotInGit params repo = do
|
||||||
findWanted FilesInGit params repo = do
|
findWanted FilesInGit params repo = do
|
||||||
files <- mapM (Git.inRepo repo) params
|
files <- mapM (Git.inRepo repo) params
|
||||||
return $ foldl (++) [] files
|
return $ foldl (++) [] files
|
||||||
|
findWanted SingleString params _ = do
|
||||||
|
return $ [unwords params]
|
||||||
findWanted RepoName params _ = do
|
findWanted RepoName params _ = do
|
||||||
return $ params
|
return $ params
|
||||||
|
|
||||||
|
@ -150,11 +152,8 @@ getCmd file = notinBackend file err $ \(key, backend) -> do
|
||||||
where
|
where
|
||||||
err = error $ "not annexed " ++ file
|
err = error $ "not annexed " ++ file
|
||||||
|
|
||||||
{- Indicates a file is wanted. -}
|
{- Indicates a file's content is not wanted anymore, and should be removed
|
||||||
wantCmd :: FilePath -> Annex ()
|
- if it's safe to do so. -}
|
||||||
wantCmd file = do error "not implemented" -- TODO
|
|
||||||
|
|
||||||
{- Indicates a file is not wanted. -}
|
|
||||||
dropCmd :: FilePath -> Annex ()
|
dropCmd :: FilePath -> Annex ()
|
||||||
dropCmd file = notinBackend file err $ \(key, backend) -> do
|
dropCmd file = notinBackend file err $ \(key, backend) -> do
|
||||||
force <- Annex.flagIsSet Force
|
force <- Annex.flagIsSet Force
|
||||||
|
@ -185,6 +184,17 @@ pushCmd reponame = do error "not implemented" -- TODO
|
||||||
pullCmd :: String -> Annex ()
|
pullCmd :: String -> Annex ()
|
||||||
pullCmd reponame = do error "not implemented" -- TODO
|
pullCmd reponame = do error "not implemented" -- TODO
|
||||||
|
|
||||||
|
{- Stores description for the repository. -}
|
||||||
|
describeCmd :: String -> Annex ()
|
||||||
|
describeCmd description = do
|
||||||
|
g <- Annex.gitRepo
|
||||||
|
u <- getUUID g
|
||||||
|
describeUUID u description
|
||||||
|
log <- uuidLog
|
||||||
|
liftIO $ Git.run g ["add", log]
|
||||||
|
Annex.flagChange NeedCommit True
|
||||||
|
liftIO $ putStrLn "description set"
|
||||||
|
|
||||||
{- Updates the LocationLog when a key's presence changes. -}
|
{- Updates the LocationLog when a key's presence changes. -}
|
||||||
logStatus :: Key -> LogStatus -> Annex ()
|
logStatus :: Key -> LogStatus -> Annex ()
|
||||||
logStatus key status = do
|
logStatus key status = do
|
||||||
|
|
10
UUID.hs
10
UUID.hs
|
@ -12,7 +12,8 @@ module UUID (
|
||||||
genUUID,
|
genUUID,
|
||||||
reposByUUID,
|
reposByUUID,
|
||||||
prettyPrintUUIDs,
|
prettyPrintUUIDs,
|
||||||
describeUUID
|
describeUUID,
|
||||||
|
uuidLog
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
@ -25,6 +26,7 @@ import qualified GitRepo as Git
|
||||||
import Types
|
import Types
|
||||||
import Locations
|
import Locations
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
import Utility
|
||||||
|
|
||||||
type UUID = String
|
type UUID = String
|
||||||
|
|
||||||
|
@ -110,7 +112,7 @@ describeUUID uuid desc = do
|
||||||
m <- uuidMap
|
m <- uuidMap
|
||||||
let m' = M.insert uuid desc m
|
let m' = M.insert uuid desc m
|
||||||
log <- uuidLog
|
log <- uuidLog
|
||||||
liftIO $ writeFile log $ serialize m'
|
liftIO $ withFileLocked log WriteMode (\h -> hPutStr h $ serialize m')
|
||||||
where
|
where
|
||||||
serialize m = unlines $ map (\(u, d) -> u++" "++d) $ M.toList m
|
serialize m = unlines $ map (\(u, d) -> u++" "++d) $ M.toList m
|
||||||
|
|
||||||
|
@ -118,7 +120,9 @@ describeUUID uuid desc = do
|
||||||
uuidMap :: Annex (M.Map UUID String)
|
uuidMap :: Annex (M.Map UUID String)
|
||||||
uuidMap = do
|
uuidMap = do
|
||||||
log <- uuidLog
|
log <- uuidLog
|
||||||
s <- liftIO $ catch (readFile log) (\error -> return "")
|
s <- liftIO $ catch
|
||||||
|
(withFileLocked log ReadMode $ \h -> hGetContentsStrict h)
|
||||||
|
(\error -> return "")
|
||||||
return $ M.fromList $ map (\l -> pair l) $ lines s
|
return $ M.fromList $ map (\l -> pair l) $ lines s
|
||||||
where
|
where
|
||||||
pair l =
|
pair l =
|
||||||
|
|
Loading…
Reference in a new issue