add fields to git-annex-shell
This commit is contained in:
parent
2d2bfe9809
commit
d1f49b0ad0
5 changed files with 42 additions and 12 deletions
|
@ -30,8 +30,8 @@ type Params = [String]
|
||||||
type Flags = [Annex ()]
|
type Flags = [Annex ()]
|
||||||
|
|
||||||
{- Runs the passed command line. -}
|
{- Runs the passed command line. -}
|
||||||
dispatch :: Bool -> Params -> [Command] -> [Option] -> String -> IO Git.Repo -> IO ()
|
dispatch :: Bool -> Params -> [Command] -> [Option] -> [(String, String)] -> String -> IO Git.Repo -> IO ()
|
||||||
dispatch fuzzyok allargs allcmds commonoptions header getgitrepo = do
|
dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do
|
||||||
setupConsole
|
setupConsole
|
||||||
r <- E.try getgitrepo :: IO (Either E.SomeException Git.Repo)
|
r <- E.try getgitrepo :: IO (Either E.SomeException Git.Repo)
|
||||||
case r of
|
case r of
|
||||||
|
@ -40,6 +40,7 @@ dispatch fuzzyok allargs allcmds commonoptions header getgitrepo = do
|
||||||
state <- Annex.new g
|
state <- Annex.new g
|
||||||
(actions, state') <- Annex.run state $ do
|
(actions, state') <- Annex.run state $ do
|
||||||
checkfuzzy
|
checkfuzzy
|
||||||
|
forM_ fields $ \(f, v) -> Annex.setField f v
|
||||||
sequence_ flags
|
sequence_ flags
|
||||||
prepCommand cmd params
|
prepCommand cmd params
|
||||||
tryRun state' cmd $ [startup] ++ actions ++ [shutdown $ cmdoneshot cmd]
|
tryRun state' cmd $ [startup] ++ actions ++ [shutdown $ cmdoneshot cmd]
|
||||||
|
|
|
@ -143,4 +143,4 @@ header :: String
|
||||||
header = "Usage: git-annex command [option ..]"
|
header = "Usage: git-annex command [option ..]"
|
||||||
|
|
||||||
run :: [String] -> IO ()
|
run :: [String] -> IO ()
|
||||||
run args = dispatch True args cmds options header Git.CurrentRepo.get
|
run args = dispatch True args cmds options [] header Git.CurrentRepo.get
|
||||||
|
|
|
@ -47,7 +47,8 @@ cmds = map adddirparam $ cmds_readonly ++ cmds_notreadonly
|
||||||
|
|
||||||
options :: [OptDescr (Annex ())]
|
options :: [OptDescr (Annex ())]
|
||||||
options = Option.common ++
|
options = Option.common ++
|
||||||
[ Option [] ["uuid"] (ReqArg checkuuid paramUUID) "repository uuid"
|
[ Option [] ["uuid"] (ReqArg checkuuid paramUUID) "local repository uuid"
|
||||||
|
, Option [] ["remote-uuid"] (ReqArg checkuuid paramUUID) "remote repository uuid"
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
checkuuid expected = getUUID >>= check
|
checkuuid expected = getUUID >>= check
|
||||||
|
@ -83,21 +84,31 @@ builtins = map cmdname cmds
|
||||||
builtin :: String -> String -> [String] -> IO ()
|
builtin :: String -> String -> [String] -> IO ()
|
||||||
builtin cmd dir params = do
|
builtin cmd dir params = do
|
||||||
checkNotReadOnly cmd
|
checkNotReadOnly cmd
|
||||||
dispatch False (cmd : filterparams params) cmds options header $
|
let (params', fields) = partitionParams params
|
||||||
|
dispatch False (cmd : params') cmds options (parseFields fields) header $
|
||||||
Git.Construct.repoAbsPath dir >>= Git.Construct.fromAbsPath
|
Git.Construct.repoAbsPath dir >>= Git.Construct.fromAbsPath
|
||||||
|
|
||||||
external :: [String] -> IO ()
|
external :: [String] -> IO ()
|
||||||
external params = do
|
external params = do
|
||||||
checkNotLimited
|
checkNotLimited
|
||||||
unlessM (boolSystem "git-shell" $ map Param $ "-c":filterparams params) $
|
unlessM (boolSystem "git-shell" $ map Param $ "-c":fst (partitionParams params)) $
|
||||||
error "git-shell failed"
|
error "git-shell failed"
|
||||||
|
|
||||||
-- Drop all args after "--".
|
{- Parameters between two -- markers are field settings, in the form:
|
||||||
-- These tend to be passed by rsync and not useful.
|
- field=value field=value
|
||||||
filterparams :: [String] -> [String]
|
-
|
||||||
filterparams [] = []
|
- Parameters after the last -- are ignored, these tend to be passed by
|
||||||
filterparams ("--":_) = []
|
- rsync and not be useful.
|
||||||
filterparams (a:as) = a:filterparams as
|
-}
|
||||||
|
partitionParams :: [String] -> ([String], [String])
|
||||||
|
partitionParams params
|
||||||
|
| length segments < 2 = (segments !! 0, [])
|
||||||
|
| otherwise = (segments !! 0, segments !! 1)
|
||||||
|
where
|
||||||
|
segments = segment (== "--") params
|
||||||
|
|
||||||
|
parseFields :: [String] -> [(String, String)]
|
||||||
|
parseFields = map (separate (== '='))
|
||||||
|
|
||||||
failure :: IO ()
|
failure :: IO ()
|
||||||
failure = error $ "bad parameters\n\n" ++ usage header cmds options
|
failure = error $ "bad parameters\n\n" ++ usage header cmds options
|
||||||
|
|
|
@ -35,3 +35,13 @@ separate c l = unbreak $ break c l
|
||||||
{- Breaks out the first line. -}
|
{- Breaks out the first line. -}
|
||||||
firstLine :: String-> String
|
firstLine :: String-> String
|
||||||
firstLine = takeWhile (/= '\n')
|
firstLine = takeWhile (/= '\n')
|
||||||
|
|
||||||
|
{- Splits a list into segments that are delimited by items matching
|
||||||
|
- a predicate. (The delimiters are not included in the segments.) -}
|
||||||
|
segment :: (a -> Bool) -> [a] -> [[a]]
|
||||||
|
segment p l = map reverse $ go [] [] l
|
||||||
|
where
|
||||||
|
go c r [] = reverse $ c:r
|
||||||
|
go c r (i:is)
|
||||||
|
| p i = go [] (c:r) is
|
||||||
|
| otherwise = go (i:c) r is
|
||||||
|
|
|
@ -61,6 +61,14 @@ to git-annex-shell are:
|
||||||
git-annex uses this to specify the UUID of the repository it was expecting
|
git-annex uses this to specify the UUID of the repository it was expecting
|
||||||
git-annex-shell to access, as a sanity check.
|
git-annex-shell to access, as a sanity check.
|
||||||
|
|
||||||
|
* -- fields=val fields=val.. --
|
||||||
|
|
||||||
|
Additional fields may be specified this way, to retain compatability with
|
||||||
|
past versions of git-annex-shell (that ignore these, but would choke
|
||||||
|
on new dashed options).
|
||||||
|
|
||||||
|
Currently used fields include remoteuuid= and associatedfile=
|
||||||
|
|
||||||
# HOOK
|
# HOOK
|
||||||
|
|
||||||
After content is received or dropped from the repository by git-annex-shell,
|
After content is received or dropped from the repository by git-annex-shell,
|
||||||
|
|
Loading…
Add table
Reference in a new issue