2016-05-13 19:11:17 +09:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
|
|
|
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
|
|
|
-
|
|
|
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
|
|
|
-
|
|
|
|
- The author(s) have dedicated all copyright and related and neighboring
|
|
|
|
- rights to this software to the public domain worldwide. This software is
|
|
|
|
- distributed without any warranty.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the CC0 Public Domain Dedication along
|
|
|
|
- with this software. If not, see
|
|
|
|
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Vervis.Handler.Repo.Darcs
|
|
|
|
( getDarcsRepoSource
|
|
|
|
, getDarcsRepoHeadChanges
|
|
|
|
, getDarcsRepoChanges
|
2016-05-13 19:58:42 +09:00
|
|
|
, getDarcsDownloadR
|
2016-05-13 19:11:17 +09:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
import Prelude
|
2016-05-13 19:11:17 +09:00
|
|
|
|
2016-05-24 05:46:54 +09:00
|
|
|
import Control.Monad.IO.Class (liftIO)
|
2016-05-13 19:11:17 +09:00
|
|
|
import Data.List (inits)
|
2016-05-24 05:46:54 +09:00
|
|
|
import Data.Maybe (fromMaybe)
|
|
|
|
import Data.Text (Text, unpack)
|
2016-05-13 19:11:17 +09:00
|
|
|
import Data.Text.Encoding (decodeUtf8With)
|
|
|
|
import Data.Text.Encoding.Error (lenientDecode)
|
|
|
|
import Database.Esqueleto
|
2016-05-24 05:46:54 +09:00
|
|
|
import System.FilePath ((</>), joinPath)
|
2016-05-13 19:58:42 +09:00
|
|
|
import System.Directory (doesFileExist)
|
2016-05-24 05:46:54 +09:00
|
|
|
import Text.Blaze.Html (Html)
|
|
|
|
import Yesod.Core (defaultLayout, setTitle)
|
|
|
|
import Yesod.Core.Content (TypedContent, typeOctet)
|
|
|
|
import Yesod.Core.Handler (sendFile, notFound)
|
2016-05-13 19:11:17 +09:00
|
|
|
|
|
|
|
import qualified Data.DList as D
|
|
|
|
import qualified Data.Set as S (member)
|
2016-05-13 19:58:42 +09:00
|
|
|
import qualified Data.Text as T (unpack)
|
2016-05-13 19:11:17 +09:00
|
|
|
import qualified Data.Text.Lazy.Encoding as L (decodeUtf8With)
|
|
|
|
|
|
|
|
import Data.ByteString.Char8.Local (takeLine)
|
|
|
|
import Text.FilePath.Local (breakExt)
|
|
|
|
import Vervis.Form.Repo
|
|
|
|
import Vervis.Foundation
|
|
|
|
import Vervis.Path
|
|
|
|
import Vervis.MediaType (chooseMediaType)
|
|
|
|
import Vervis.Model
|
2016-05-24 05:46:54 +09:00
|
|
|
import Vervis.Model.Ident
|
2016-05-13 19:11:17 +09:00
|
|
|
import Vervis.Model.Repo
|
|
|
|
import Vervis.Paginate
|
|
|
|
import Vervis.Readme
|
|
|
|
import Vervis.Render
|
|
|
|
import Vervis.Settings
|
|
|
|
import Vervis.SourceTree
|
|
|
|
import Vervis.Style
|
|
|
|
import Vervis.Widget.Repo
|
|
|
|
|
|
|
|
import qualified Darcs.Local.Repository as D (createRepo)
|
|
|
|
import qualified Data.ByteString.Lazy as BL (ByteString)
|
|
|
|
import qualified Vervis.Darcs as D (readSourceView, readChangesView)
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getDarcsRepoSource :: Repo -> ShrIdent -> RpIdent -> [Text] -> Handler Html
|
2016-05-13 19:11:17 +09:00
|
|
|
getDarcsRepoSource repository user repo dir = do
|
|
|
|
path <- askRepoDir user repo
|
|
|
|
msv <- liftIO $ D.readSourceView path dir
|
|
|
|
case msv of
|
|
|
|
Nothing -> notFound
|
|
|
|
Just sv -> do
|
|
|
|
let parent = if null dir then [] else init dir
|
|
|
|
dirs = zip parent (tail $ inits parent)
|
2016-05-24 05:46:54 +09:00
|
|
|
defaultLayout $(widgetFile "repo/source-darcs")
|
2016-05-13 19:11:17 +09:00
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getDarcsRepoHeadChanges :: ShrIdent -> RpIdent -> Handler Html
|
2016-05-13 19:11:17 +09:00
|
|
|
getDarcsRepoHeadChanges shar repo = do
|
|
|
|
path <- askRepoDir shar repo
|
|
|
|
(entries, navModel) <- getPageAndNav $
|
|
|
|
\ o l -> do
|
|
|
|
mv <- liftIO $ D.readChangesView path o l
|
|
|
|
case mv of
|
|
|
|
Nothing -> notFound
|
|
|
|
Just v -> return v
|
|
|
|
let changes = changesW entries
|
|
|
|
pageNav = navWidget navModel
|
|
|
|
defaultLayout $(widgetFile "repo/changes-darcs")
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getDarcsRepoChanges :: ShrIdent -> RpIdent -> Text -> Handler Html
|
2016-05-13 19:11:17 +09:00
|
|
|
getDarcsRepoChanges shar repo tag = notFound
|
2016-05-13 19:58:42 +09:00
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getDarcsDownloadR :: ShrIdent -> RpIdent -> [Text] -> Handler TypedContent
|
2016-05-13 19:58:42 +09:00
|
|
|
getDarcsDownloadR shar repo dir = do
|
|
|
|
path <- askRepoDir shar repo
|
|
|
|
let darcsDir = path </> "_darcs"
|
|
|
|
filePath = darcsDir </> joinPath (map T.unpack dir)
|
|
|
|
exists <- liftIO $ doesFileExist filePath
|
|
|
|
if exists
|
|
|
|
then sendFile typeOctet filePath
|
|
|
|
else notFound
|