darcs repository web UI and hosting app. This is the main darcsden trunk, which also runs hub.darcs.net. (https://hub.darcs.net)

root / src / DarcsDen / Darcs.hs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{-# LANGUAGE ScopedTypeVariables,CPP,FlexibleInstances #-}
module DarcsDen.Darcs where

import Control.Exception as E
import Control.Monad
import Control.Monad.Trans
import qualified Darcs.Repository as R
import qualified Darcs.Repository.Flags as F
import Darcs.UI.Commands (DarcsCommand)
import qualified Darcs.UI.Commands.Clone as C
import qualified Darcs.UI.Options as O
import qualified Darcs.UI.Options.All as O
import Darcs.UI.RunCommand (runWithHooks)
import Darcs.Util.File (withCurrentDirectory)
import Darcs.Util.Path (ioAbsolute)
import DarcsDen.Settings
import System.Directory (createDirectoryIfMissing, removeDirectoryRecursive)


sanityDarcs :: DarcsCommand -> O.Config -> [String] -> IO ()
sanityDarcs cmd opts args = do
  cwd <- ioAbsolute "."
  runWithHooks cmd (cwd,cwd) (makeQuiet opts) args

makeQuiet :: O.Config -> O.Config
makeQuiet = O.unparseOpt O.verbosity O.Quiet

getTo :: MonadIO m => String -> String -> m ()
getTo from to = liftIO $ sanityDarcs C.get [] [from, to]

data RepoType = Darcs1 | Darcs2

-- could move this to Settings, but there's only
-- one realistic default at present
repoTypeDefault :: RepoType
repoTypeDefault = Darcs2

repoTypeDarcs1 :: (?settings :: Settings) => RepoType
repoTypeDarcs1 =
   if supportdarcs1
     then Darcs1
     else error "darcs 1 repos are not supported by this installation"

repoTypeFromString :: (?settings :: Settings) => Maybe String -> RepoType
repoTypeFromString Nothing = repoTypeDefault
repoTypeFromString (Just "darcs-1") = repoTypeDarcs1
repoTypeFromString (Just "darcs-2") = Darcs2
repoTypeFromString (Just s) = error $ "unknown repo type " ++ s

repoTypeFromDarcs1Flag ::  (?settings :: Settings) => Bool -> RepoType
repoTypeFromDarcs1Flag False = repoTypeDefault
repoTypeFromDarcs1Flag True = repoTypeDarcs1

init :: (MonadIO m, ?settings :: Settings) => RepoType -> String -> m ()
init repoType to = liftIO $ do
  createDirectoryIfMissing True to
  withCurrentDirectory to (void $ R.createRepository useDarcs1 F.WithWorkingDir F.YesPatchIndex F.YesUseCache) `E.catch` \(_ :: IOException) ->
    when deletefiles $ removeDirectoryRecursive to
      where
        useDarcs1 =
          case repoType of
            Darcs1 -> F.PatchFormat1
            Darcs2 -> F.PatchFormat2