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 ()]
|
||||
|
||||
{- Runs the passed command line. -}
|
||||
dispatch :: Bool -> Params -> [Command] -> [Option] -> String -> IO Git.Repo -> IO ()
|
||||
dispatch fuzzyok allargs allcmds commonoptions header getgitrepo = do
|
||||
dispatch :: Bool -> Params -> [Command] -> [Option] -> [(String, String)] -> String -> IO Git.Repo -> IO ()
|
||||
dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do
|
||||
setupConsole
|
||||
r <- E.try getgitrepo :: IO (Either E.SomeException Git.Repo)
|
||||
case r of
|
||||
|
@ -40,6 +40,7 @@ dispatch fuzzyok allargs allcmds commonoptions header getgitrepo = do
|
|||
state <- Annex.new g
|
||||
(actions, state') <- Annex.run state $ do
|
||||
checkfuzzy
|
||||
forM_ fields $ \(f, v) -> Annex.setField f v
|
||||
sequence_ flags
|
||||
prepCommand cmd params
|
||||
tryRun state' cmd $ [startup] ++ actions ++ [shutdown $ cmdoneshot cmd]
|
||||
|
|
|
@ -143,4 +143,4 @@ header :: String
|
|||
header = "Usage: git-annex command [option ..]"
|
||||
|
||||
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 = 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
|
||||
checkuuid expected = getUUID >>= check
|
||||
|
@ -83,21 +84,31 @@ builtins = map cmdname cmds
|
|||
builtin :: String -> String -> [String] -> IO ()
|
||||
builtin cmd dir params = do
|
||||
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
|
||||
|
||||
external :: [String] -> IO ()
|
||||
external params = do
|
||||
checkNotLimited
|
||||
unlessM (boolSystem "git-shell" $ map Param $ "-c":filterparams params) $
|
||||
unlessM (boolSystem "git-shell" $ map Param $ "-c":fst (partitionParams params)) $
|
||||
error "git-shell failed"
|
||||
|
||||
-- Drop all args after "--".
|
||||
-- These tend to be passed by rsync and not useful.
|
||||
filterparams :: [String] -> [String]
|
||||
filterparams [] = []
|
||||
filterparams ("--":_) = []
|
||||
filterparams (a:as) = a:filterparams as
|
||||
{- Parameters between two -- markers are field settings, in the form:
|
||||
- field=value field=value
|
||||
-
|
||||
- Parameters after the last -- are ignored, these tend to be passed by
|
||||
- rsync and not be useful.
|
||||
-}
|
||||
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 = 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. -}
|
||||
firstLine :: String-> String
|
||||
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-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
|
||||
|
||||
After content is received or dropped from the repository by git-annex-shell,
|
||||
|
|
Loading…
Reference in a new issue