Skip to content

Commit

Permalink
Sync repo: Support darcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
strake committed May 9, 2021
1 parent 0d0f9e9 commit 1fe4655
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 33 additions & 2 deletions cabal-install/src/Distribution/Client/VCS.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns, RecordWildCards, RankNTypes #-}
module Distribution.Client.VCS (
-- * VCS driver type
Expand Down Expand Up @@ -51,14 +52,22 @@ import Distribution.Version
( mkVersion )
import qualified Distribution.PackageDescription as PD

import Control.Applicative
( liftA2 )
import Control.Exception
( throw )
import Control.Monad.Trans
( liftIO )
import qualified Data.Char as Char
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.
Expand Down Expand Up @@ -305,7 +314,29 @@ 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 = do
removeDirectoryRecursive localDir `catch` liftA2 unless isDoesNotExistError throw
darcs (takeDirectory localDir) cloneArgs
where
darcs :: FilePath -> [String] -> IO ()
darcs cwd args = runProgramInvocation 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") {
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/sync-repo-darcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
synopsis: Sync repo darcs
prs: #7137

0 comments on commit 1fe4655

Please sign in to comment.