Skip to content
Snippets Groups Projects
Unverified Commit 8f5b2f04 authored by Emily Pillmore's avatar Emily Pillmore :ocean: Committed by GitHub
Browse files

Merge pull request #7137 from strake/sync-repo-darcs

Sync repo darcs
parents ea830d70 47ae4f47
No related branches found
No related tags found
No related merge requests found
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NamedFieldPuns, RecordWildCards, RankNTypes #-}
module Distribution.Client.VCS (
-- * VCS driver type
......@@ -45,20 +47,29 @@ import Distribution.Simple.Program
( Program(programFindVersion)
, ConfiguredProgram(programVersion)
, simpleProgram, findProgramVersion
, ProgramInvocation(..), programInvocation, runProgramInvocation
, ProgramInvocation(..), programInvocation, runProgramInvocation, getProgramInvocationOutput
, emptyProgramDb, requireProgram )
import Distribution.Version
( mkVersion )
import qualified Distribution.PackageDescription as PD
import Control.Applicative
( liftA2 )
import Control.Exception
( throw, try )
import Control.Monad.Trans
( liftIO )
import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import System.FilePath
( takeDirectory )
import System.Directory
( doesDirectoryExist )
( doesDirectoryExist
, removeDirectoryRecursive
)
import System.IO.Error
( isDoesNotExistError )
-- | A driver for a version control system, e.g. git, darcs etc.
......@@ -306,7 +317,41 @@ vcsDarcs =
vcsSyncRepos :: Verbosity -> ConfiguredProgram
-> [(SourceRepositoryPackage f, FilePath)] -> IO [MonitorFilePath]
vcsSyncRepos _v _p _rs = fail "sync repo not yet supported for darcs"
vcsSyncRepos _ _ [] = return []
vcsSyncRepos verbosity prog ((primaryRepo, primaryLocalDir) : secondaryRepos) =
monitors <$ do
vcsSyncRepo verbosity prog primaryRepo primaryLocalDir Nothing
for_ secondaryRepos $ \ (repo, localDir) ->
vcsSyncRepo verbosity prog repo localDir $ Just primaryLocalDir
where
dirs = primaryLocalDir : (snd <$> secondaryRepos)
monitors = monitorDirectoryExistence <$> dirs
vcsSyncRepo verbosity prog SourceRepositoryPackage{..} localDir _peer =
try (lines <$> darcsWithOutput localDir ["log", "--last", "1"]) >>= \ case
Right (_:_:_:x:_)
| Just tag <- (List.stripPrefix "tagged " . List.dropWhile Char.isSpace) x
, Just tag' <- srpTag
, tag == tag' -> pure ()
Left e | not (isDoesNotExistError e) -> throw e
_ -> do
removeDirectoryRecursive localDir `catch` liftA2 unless isDoesNotExistError throw
darcs (takeDirectory localDir) cloneArgs
where
darcs :: FilePath -> [String] -> IO ()
darcs = darcs' runProgramInvocation
darcsWithOutput :: FilePath -> [String] -> IO String
darcsWithOutput = darcs' getProgramInvocationOutput
darcs' f cwd args = f verbosity (programInvocation prog args)
{ progInvokeCwd = Just cwd }
cloneArgs = ["clone"] ++ tagArgs ++ [srpLocation, localDir] ++ verboseArg
tagArgs = case srpTag of
Nothing -> []
Just tag -> ["-t" ++ tag]
verboseArg = [ "--quiet" | verbosity < Verbosity.normal ]
darcsProgram :: Program
darcsProgram = (simpleProgram "darcs") {
......
synopsis: Sync repo darcs
prs: #7137
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment