mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-29 02:24:52 +09:00
Enable darcs-push-over-SSH using the darcs executable
This commit is contained in:
parent
3ed04941e8
commit
a4c8a80945
1 changed files with 22 additions and 25 deletions
|
@ -69,15 +69,9 @@ data RepoSpec
|
||||||
| SpecRepo Text
|
| SpecRepo Text
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
--data DarcsFile
|
|
||||||
-- = DarcsFormat
|
|
||||||
-- | DarcsMotd
|
|
||||||
-- | DarcsInventory
|
|
||||||
-- deriving Show
|
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
-- = DarcsCopy RepoSpec DarcsFile
|
|
||||||
= DarcsTransferMode RepoSpec
|
= DarcsTransferMode RepoSpec
|
||||||
|
| DarcsApply RepoSpec
|
||||||
| GitUploadPack RepoSpec
|
| GitUploadPack RepoSpec
|
||||||
| GitReceivePack RepoSpec
|
| GitReceivePack RepoSpec
|
||||||
deriving Show
|
deriving Show
|
||||||
|
@ -143,11 +137,13 @@ authorize (PublicKey name key) = do
|
||||||
--TOD TODO TODO check paths for safety... no /./ or /../ and so on
|
--TOD TODO TODO check paths for safety... no /./ or /../ and so on
|
||||||
|
|
||||||
darcsRepoSpecP :: Parser RepoSpec
|
darcsRepoSpecP :: Parser RepoSpec
|
||||||
darcsRepoSpecP = f <$> part <* char '/' <*> optional (part <* char '/')
|
darcsRepoSpecP = f <$>
|
||||||
|
part <*>
|
||||||
|
optional (char '/' *> optional (part <* optional (char '/')))
|
||||||
where
|
where
|
||||||
f repo Nothing = SpecRepo repo
|
f sharer (Just (Just repo)) = SpecUserRepo sharer repo
|
||||||
f sharer (Just repo) = SpecUserRepo sharer repo
|
f repo _ = SpecRepo repo
|
||||||
part = takeWhile1 (/= '/')
|
part = takeWhile1 $ \ c -> c /= '/' && c /= '\''
|
||||||
|
|
||||||
gitRepoSpecP :: Parser RepoSpec
|
gitRepoSpecP :: Parser RepoSpec
|
||||||
gitRepoSpecP = f <$> (msh *> part) <*> optional (char '/' *> part)
|
gitRepoSpecP = f <$> (msh *> part) <*> optional (char '/' *> part)
|
||||||
|
@ -160,6 +156,8 @@ gitRepoSpecP = f <$> (msh *> part) <*> optional (char '/' *> part)
|
||||||
actionP :: Parser Action
|
actionP :: Parser Action
|
||||||
actionP = DarcsTransferMode <$>
|
actionP = DarcsTransferMode <$>
|
||||||
("darcs transfer-mode --repodir " *> darcsRepoSpecP)
|
("darcs transfer-mode --repodir " *> darcsRepoSpecP)
|
||||||
|
<|> DarcsApply <$>
|
||||||
|
("darcs apply --all --repodir '" *> darcsRepoSpecP <* char '\'')
|
||||||
<|> GitUploadPack <$>
|
<|> GitUploadPack <$>
|
||||||
("git-upload-pack '" *> gitRepoSpecP <* char '\'')
|
("git-upload-pack '" *> gitRepoSpecP <* char '\'')
|
||||||
<|> GitReceivePack <$>
|
<|> GitReceivePack <$>
|
||||||
|
@ -216,28 +214,27 @@ whenGitRepoExists repoPath action = do
|
||||||
then action
|
then action
|
||||||
else return $ ARFail "No such git repository"
|
else return $ ARFail "No such git repository"
|
||||||
|
|
||||||
--darcsFilePath :: DarcsFile -> FilePath
|
|
||||||
--darcsFilePath DarcsFormat = "_darcs" </> "format"
|
|
||||||
--darcsFilePath DarcsMotd = "_darcs" </> "prefs" </> "motd"
|
|
||||||
--darcsFilePath DarcsInventory = "_darcs" </> "format"
|
|
||||||
|
|
||||||
runAction :: FilePath -> Bool -> Action -> Channel ActionResult
|
runAction :: FilePath -> Bool -> Action -> Channel ActionResult
|
||||||
runAction repoDir _wantReply action =
|
runAction repoDir _wantReply action =
|
||||||
case action of
|
case action of
|
||||||
--DarcsCopy spec file -> do
|
|
||||||
-- (_sharer, _repo, repoPath) <- resolveSpec' repoDir spec
|
|
||||||
-- let filePath = repoPath </> darcsFilePath file
|
|
||||||
-- exists <- liftIO $ doesFileExist filePath
|
|
||||||
-- if exists
|
|
||||||
-- then do
|
|
||||||
-- execute "scp" ["-f", filePath]
|
|
||||||
-- return ARProcess
|
|
||||||
-- else return $ ARFail "No such file in the repo"
|
|
||||||
DarcsTransferMode spec -> do
|
DarcsTransferMode spec -> do
|
||||||
(_sharer, _repo, repoPath) <- resolveSpec' repoDir spec
|
(_sharer, _repo, repoPath) <- resolveSpec' repoDir spec
|
||||||
whenDarcsRepoExists repoPath $ do
|
whenDarcsRepoExists repoPath $ do
|
||||||
execute "darcs" ["transfer-mode", "--repodir", repoPath]
|
execute "darcs" ["transfer-mode", "--repodir", repoPath]
|
||||||
return ARProcess
|
return ARProcess
|
||||||
|
DarcsApply spec -> do
|
||||||
|
(sharer, repo, repoPath) <- resolveSpec' repoDir spec
|
||||||
|
-- Now we need to check whether the authenticated user (can get its
|
||||||
|
-- details with 'askAuthDetails') has write access to the repo.
|
||||||
|
-- This is currently true iff the authenticated user and the repo
|
||||||
|
-- sharer have the same ID. Since sharer names are unique, it's
|
||||||
|
-- enough to compare them.
|
||||||
|
userName <- T.pack . authUser <$> askAuthDetails
|
||||||
|
if userName == sharer
|
||||||
|
then whenDarcsRepoExists repoPath $ do
|
||||||
|
execute "darcs" ["apply", "--all", "--repodir", repoPath]
|
||||||
|
return ARProcess
|
||||||
|
else return $ ARFail "You can't push to this repository"
|
||||||
GitUploadPack spec -> do
|
GitUploadPack spec -> do
|
||||||
(_sharer, _repo, repoPath) <- resolveSpec' repoDir spec
|
(_sharer, _repo, repoPath) <- resolveSpec' repoDir spec
|
||||||
whenGitRepoExists repoPath $ do
|
whenGitRepoExists repoPath $ do
|
||||||
|
|
Loading…
Reference in a new issue