2016-05-05 07:29:19 +00:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
2022-06-25 19:59:26 +00:00
|
|
|
- Written in 2016, 2018, 2019, 2020, 2022
|
|
|
|
- by fr33domlover <fr33domlover@riseup.net>.
|
2016-05-05 07:29:19 +00:00
|
|
|
-
|
|
|
|
- ♡ 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.Darcs
|
2022-09-16 13:47:10 +00:00
|
|
|
( readSourceView
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
--, readWikiView
|
2022-09-16 13:47:10 +00:00
|
|
|
, readChangesView
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
--, lastChange
|
2022-09-16 12:46:52 +00:00
|
|
|
, readPatch
|
2022-09-16 11:41:58 +00:00
|
|
|
, writePostApplyHooks
|
2022-09-24 21:15:40 +00:00
|
|
|
, canApplyDarcsPatch
|
2022-09-24 09:04:10 +00:00
|
|
|
, applyDarcsPatch
|
2016-05-05 07:29:19 +00:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2016-06-04 06:57:54 +00:00
|
|
|
import Prelude hiding (lookup)
|
2016-05-05 07:29:19 +00:00
|
|
|
|
2016-06-04 06:57:54 +00:00
|
|
|
import Control.Applicative ((<|>))
|
2019-10-07 14:05:52 +00:00
|
|
|
import Control.Monad.IO.Class
|
2016-05-13 08:49:19 +00:00
|
|
|
import Control.Monad.Trans.Class (lift)
|
2022-06-25 19:59:26 +00:00
|
|
|
import Control.Monad.Trans.Except
|
2016-07-02 08:51:29 +00:00
|
|
|
import Darcs.Util.Path
|
|
|
|
import Darcs.Util.Tree
|
|
|
|
import Darcs.Util.Tree.Hashed
|
2019-10-31 10:11:13 +00:00
|
|
|
import Data.Bifunctor
|
2016-06-04 06:57:54 +00:00
|
|
|
import Data.Bool (bool)
|
2018-07-09 19:12:11 +00:00
|
|
|
import Data.ByteString (ByteString)
|
2019-10-07 14:05:52 +00:00
|
|
|
import Data.Foldable hiding (find)
|
2019-10-31 10:11:13 +00:00
|
|
|
import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
|
2018-07-08 14:45:35 +00:00
|
|
|
import Data.Maybe (listToMaybe, mapMaybe, fromMaybe)
|
2016-05-05 07:29:19 +00:00
|
|
|
import Data.Text (Text)
|
2018-07-08 14:45:35 +00:00
|
|
|
import Data.Text.Encoding (encodeUtf8, decodeUtf8With, decodeUtf8)
|
2016-05-05 07:29:19 +00:00
|
|
|
import Data.Text.Encoding.Error (strictDecode)
|
2018-04-09 22:00:01 +00:00
|
|
|
import Data.Time.Clock (UTCTime, getCurrentTime, diffUTCTime)
|
2016-05-05 07:29:19 +00:00
|
|
|
import Data.Traversable (for)
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
import Database.Persist
|
2018-03-20 23:45:09 +00:00
|
|
|
import Development.Darcs.Internal.Hash.Codec
|
2018-07-08 14:45:35 +00:00
|
|
|
import Development.Darcs.Internal.Hash.Types
|
2018-03-20 23:45:09 +00:00
|
|
|
import Development.Darcs.Internal.Inventory.Parser
|
|
|
|
import Development.Darcs.Internal.Inventory.Read
|
|
|
|
import Development.Darcs.Internal.Inventory.Types
|
|
|
|
import Development.Darcs.Internal.Patch.Types
|
2022-06-25 19:59:26 +00:00
|
|
|
import System.Exit
|
2016-05-05 07:29:19 +00:00
|
|
|
import System.FilePath ((</>))
|
2022-06-25 19:59:26 +00:00
|
|
|
import System.Process.Typed
|
2018-07-08 14:45:35 +00:00
|
|
|
import Text.Email.Validate (emailAddress)
|
2016-05-05 07:29:19 +00:00
|
|
|
|
2018-07-08 14:45:35 +00:00
|
|
|
import qualified Data.Attoparsec.Text as A
|
2019-10-31 10:11:13 +00:00
|
|
|
import qualified Data.ByteString as B
|
2022-06-25 19:59:26 +00:00
|
|
|
import qualified Data.ByteString.Lazy as BL
|
2018-07-08 14:45:35 +00:00
|
|
|
import qualified Data.ByteString.Base16 as B16 (encode, decode)
|
2016-05-05 07:29:19 +00:00
|
|
|
import qualified Data.Foldable as F (find)
|
2019-10-31 10:11:13 +00:00
|
|
|
import qualified Data.List.NonEmpty as NE
|
|
|
|
import qualified Data.Text as T
|
2022-06-25 19:59:26 +00:00
|
|
|
import qualified Data.Text.Encoding as TE
|
2018-07-08 14:45:35 +00:00
|
|
|
import qualified Data.Vector as V (empty)
|
2019-10-07 14:05:52 +00:00
|
|
|
import qualified Database.Esqueleto as E
|
|
|
|
|
2018-07-08 14:45:35 +00:00
|
|
|
import qualified Development.Darcs.Internal.Patch.Parser as P
|
2016-05-05 07:29:19 +00:00
|
|
|
|
2019-10-20 09:19:49 +00:00
|
|
|
import Network.FedURI
|
|
|
|
import Yesod.ActivityPub
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
import Yesod.Hashids
|
2019-10-07 14:05:52 +00:00
|
|
|
import Yesod.MonadSite
|
|
|
|
|
2016-05-08 14:28:03 +00:00
|
|
|
import Darcs.Local.Repository
|
2016-05-13 08:49:19 +00:00
|
|
|
import Data.Either.Local (maybeRight)
|
2016-05-08 14:28:03 +00:00
|
|
|
import Data.EventTime.Local
|
2018-07-09 19:12:11 +00:00
|
|
|
import Data.List.Local
|
2019-10-31 10:11:13 +00:00
|
|
|
import Data.List.NonEmpty.Local
|
2020-05-24 09:17:49 +00:00
|
|
|
import Data.Patch.Local hiding (Patch)
|
2016-05-08 14:28:03 +00:00
|
|
|
import Data.Text.UTF8.Local (decodeStrict)
|
|
|
|
import Data.Time.Clock.Local ()
|
2022-09-24 09:04:10 +00:00
|
|
|
import System.Process.Typed.Local
|
2018-07-09 19:12:11 +00:00
|
|
|
|
2020-05-24 09:17:49 +00:00
|
|
|
import qualified Data.Patch.Local as DP
|
2022-06-25 19:59:26 +00:00
|
|
|
import qualified Data.Text.UTF8.Local as TU
|
2020-05-24 09:17:49 +00:00
|
|
|
|
2016-05-08 14:28:03 +00:00
|
|
|
import Vervis.Changes
|
2019-10-07 14:05:52 +00:00
|
|
|
import Vervis.Foundation
|
|
|
|
import Vervis.Model
|
|
|
|
import Vervis.Model.Ident
|
2020-08-14 21:16:33 +00:00
|
|
|
import Development.PatchMediaType
|
2019-10-07 14:05:52 +00:00
|
|
|
import Vervis.Path
|
2016-05-05 07:29:19 +00:00
|
|
|
import Vervis.Readme
|
2019-10-07 14:05:52 +00:00
|
|
|
import Vervis.Settings
|
2016-05-05 07:29:19 +00:00
|
|
|
import Vervis.SourceTree
|
|
|
|
|
|
|
|
dirToAnchoredPath :: [EntryName] -> AnchoredPath
|
2018-05-16 00:02:54 +00:00
|
|
|
dirToAnchoredPath = AnchoredPath . map (decodeWhiteName . encodeUtf8)
|
2016-05-05 07:29:19 +00:00
|
|
|
|
|
|
|
matchType :: ItemType -> EntryType
|
|
|
|
matchType TreeType = TypeTree
|
|
|
|
matchType BlobType = TypeBlob
|
|
|
|
|
|
|
|
nameToText :: Name -> Text
|
2018-05-16 00:02:54 +00:00
|
|
|
nameToText = decodeUtf8With strictDecode . encodeWhiteName
|
2016-05-05 07:29:19 +00:00
|
|
|
|
|
|
|
itemToEntry :: Name -> TreeItem IO -> DirEntry
|
|
|
|
itemToEntry name item = DirEntry (matchType $ itemType item) (nameToText name)
|
|
|
|
|
|
|
|
findReadme :: [(Name, TreeItem IO)] -> IO (Maybe (Text, BL.ByteString))
|
|
|
|
findReadme pairs =
|
|
|
|
case F.find (isReadme . nameToText . fst) pairs of
|
|
|
|
Nothing -> return Nothing
|
|
|
|
Just (name, item) ->
|
|
|
|
case item of
|
|
|
|
File (Blob load _hash) -> do
|
|
|
|
content <- load
|
|
|
|
return $ Just (nameToText name, content)
|
|
|
|
_ -> return Nothing
|
|
|
|
|
|
|
|
itemToSourceView :: EntryName -> TreeItem IO -> IO (SourceView BL.ByteString)
|
|
|
|
itemToSourceView name (File (Blob load _hash)) = do
|
|
|
|
content <- load
|
|
|
|
return $ SourceFile $ FileView name content
|
|
|
|
itemToSourceView name (SubTree tree) = do
|
|
|
|
let items = listImmediate tree
|
|
|
|
mreadme <- findReadme items
|
|
|
|
return $ SourceDir DirectoryView
|
|
|
|
{ dvName = Just name
|
|
|
|
, dvEntries = map (uncurry itemToEntry) items
|
|
|
|
, dvReadme = mreadme
|
|
|
|
}
|
|
|
|
itemToSourceView _name (Stub _load _hash) = error "supposed to be expanded"
|
|
|
|
|
2016-06-04 06:57:54 +00:00
|
|
|
readStubbedTree :: FilePath -> IO (Tree IO)
|
|
|
|
readStubbedTree path = do
|
|
|
|
let darcsDir = path </> "_darcs"
|
|
|
|
(msize, hash) <- readPristineRoot darcsDir
|
|
|
|
let pristineDir = darcsDir </> "pristine.hashed"
|
|
|
|
readDarcsHashed pristineDir (msize, hash)
|
|
|
|
|
2016-05-05 07:29:19 +00:00
|
|
|
readSourceView
|
|
|
|
:: FilePath
|
|
|
|
-- ^ Repository path
|
|
|
|
-> [EntryName]
|
|
|
|
-- ^ Path in the source tree pointing to a file or directory
|
|
|
|
-> IO (Maybe (SourceView Widget))
|
|
|
|
readSourceView path dir = do
|
2016-06-04 06:57:54 +00:00
|
|
|
stubbedTree <- readStubbedTree path
|
2016-05-05 07:29:19 +00:00
|
|
|
msv <- if null dir
|
|
|
|
then do
|
|
|
|
let items = listImmediate stubbedTree
|
|
|
|
mreadme <- findReadme items
|
|
|
|
return $ Just $ SourceDir DirectoryView
|
|
|
|
{ dvName = Nothing
|
|
|
|
, dvEntries = map (uncurry itemToEntry) items
|
|
|
|
, dvReadme = mreadme
|
|
|
|
}
|
|
|
|
else do
|
|
|
|
let anch = dirToAnchoredPath dir
|
|
|
|
expandedTree <- expandPath stubbedTree anch
|
|
|
|
let mitem = find expandedTree anch
|
|
|
|
for mitem $ itemToSourceView (last dir)
|
|
|
|
return $ renderSources dir <$> msv
|
2016-05-08 14:28:03 +00:00
|
|
|
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
{-
|
2016-06-04 06:57:54 +00:00
|
|
|
readWikiView
|
|
|
|
:: (EntryName -> EntryName -> Maybe Text)
|
|
|
|
-- ^ Page name predicate. Returns 'Nothing' for a file which isn't a page.
|
|
|
|
-- For a page file, returns 'Just' the page name, which is the filename
|
|
|
|
-- with some parts possibly removed or added. For example, you may wish to
|
|
|
|
-- remove any extensions, replace underscores with spaces and so on.
|
|
|
|
-> (EntryName -> Bool)
|
|
|
|
-- ^ Main page predicate. This is used to pick a top-level page to display
|
|
|
|
-- as the wiki root page.
|
|
|
|
-> FilePath
|
|
|
|
-- ^ Repository path.
|
|
|
|
-> [EntryName]
|
|
|
|
-- ^ Path in the source tree pointing to a file. The last component doesn't
|
|
|
|
-- have to be the full name of the file though, but it much match the page
|
|
|
|
-- predicate for the actual file to be found.
|
|
|
|
-> IO (Maybe WikiView)
|
|
|
|
readWikiView isPage isMain path dir = do
|
|
|
|
stubbedTree <- readStubbedTree path
|
|
|
|
let (parent, ispage, mfile) =
|
|
|
|
if null dir
|
|
|
|
then
|
|
|
|
( []
|
|
|
|
, bool Nothing (Just Nothing) . isMain
|
|
|
|
, Nothing
|
|
|
|
)
|
|
|
|
else
|
|
|
|
( init dir
|
|
|
|
, maybe Nothing (Just . Just) . isPage lst
|
2018-05-16 00:02:54 +00:00
|
|
|
, Just $ decodeWhiteName $ encodeUtf8 lst
|
2016-06-04 06:57:54 +00:00
|
|
|
)
|
|
|
|
where
|
|
|
|
lst = last dir
|
|
|
|
anch = dirToAnchoredPath parent
|
|
|
|
matchBlob f (n, (File (Blob load _))) = f (nameToText n) load
|
|
|
|
matchBlob _ _ = Nothing
|
|
|
|
matchBlob' f (File (Blob load _)) = Just $ f load
|
|
|
|
matchBlob' _ _ = Nothing
|
|
|
|
page name load = (,) load . Just <$> ispage name
|
|
|
|
matchP = listToMaybe . mapMaybe (matchBlob page) . listImmediate
|
|
|
|
matchF t = mfile >>= lookup t >>= matchBlob' (flip (,) Nothing)
|
|
|
|
expandedTree <- expandPath stubbedTree anch
|
|
|
|
let mpage = case find expandedTree anch of
|
|
|
|
Nothing -> Nothing
|
|
|
|
Just (File _) -> Nothing
|
|
|
|
Just (Stub _ _) -> error "supposed to be expanded"
|
|
|
|
Just (SubTree tree) -> matchP tree <|> matchF tree
|
|
|
|
mkview Nothing b = WikiViewRaw b
|
|
|
|
mkview (Just mt) b = WikiViewPage mt b
|
|
|
|
for mpage $ \ (load, mmtitle) -> mkview mmtitle <$> load
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
-}
|
2016-06-04 06:57:54 +00:00
|
|
|
|
2016-05-08 14:28:03 +00:00
|
|
|
readChangesView
|
|
|
|
:: FilePath
|
|
|
|
-- ^ Repository path
|
2016-05-13 08:49:19 +00:00
|
|
|
-> Int
|
|
|
|
-- ^ Offset, i.e. latest patches to skip
|
|
|
|
-> Int
|
|
|
|
-- ^ Limit, i.e. how many latest patches to take after the offset
|
|
|
|
-> IO (Maybe (Int, [LogEntry]))
|
|
|
|
-- ^ Total number of changes, and view of the chosen subset
|
|
|
|
readChangesView path off lim = fmap maybeRight $ runExceptT $ do
|
2016-05-17 20:34:22 +00:00
|
|
|
total <- ExceptT $ readLatestInventory path latestInventorySizeP
|
2016-05-13 08:49:19 +00:00
|
|
|
let off' = total - off - lim
|
2016-05-17 20:34:22 +00:00
|
|
|
ps <- ExceptT $ readLatestInventory path $ latestInventoryPageP off' lim
|
2016-05-13 08:49:19 +00:00
|
|
|
now <- lift getCurrentTime
|
2018-05-24 21:45:01 +00:00
|
|
|
let toLE (pi, h, _) = LogEntry
|
2016-05-13 08:49:19 +00:00
|
|
|
{ leAuthor =
|
|
|
|
T.stripEnd $ T.takeWhile (/= '<') $ piAuthor pi
|
2018-05-24 21:45:01 +00:00
|
|
|
, leHash = decodeStrict $ encodePatchInfoHash h
|
2016-05-13 08:49:19 +00:00
|
|
|
, leMessage = piTitle pi
|
|
|
|
, leTime =
|
2018-03-31 22:04:33 +00:00
|
|
|
( piTime pi
|
|
|
|
, intervalToEventTime $
|
|
|
|
FriendlyConvert $
|
|
|
|
now `diffUTCTime` piTime pi
|
|
|
|
)
|
2016-05-13 08:49:19 +00:00
|
|
|
}
|
2018-05-24 21:45:01 +00:00
|
|
|
return (total, map toLE $ reverse $ snd ps)
|
2018-04-09 22:00:01 +00:00
|
|
|
|
|
|
|
lastChange :: FilePath -> UTCTime -> IO (Maybe EventTime)
|
|
|
|
lastChange path now = fmap maybeRight $ runExceptT $ do
|
|
|
|
total <- ExceptT $ readLatestInventory path latestInventorySizeP
|
|
|
|
let lim = 1
|
|
|
|
off = total - lim
|
|
|
|
(_, l) <- ExceptT $ readLatestInventory path $ latestInventoryPageP off lim
|
|
|
|
return $ case reverse l of
|
2018-05-24 21:45:01 +00:00
|
|
|
[] -> Never
|
|
|
|
(pi, _ih, _ch) : _ ->
|
2018-04-09 22:00:01 +00:00
|
|
|
intervalToEventTime $
|
|
|
|
FriendlyConvert $
|
|
|
|
now `diffUTCTime` piTime pi
|
2018-07-07 16:05:10 +00:00
|
|
|
|
2019-10-31 10:11:13 +00:00
|
|
|
data Change
|
|
|
|
= AddFile FilePath
|
|
|
|
| AddDir FilePath
|
|
|
|
| Move FilePath FilePath
|
|
|
|
| RemoveFile FilePath
|
|
|
|
| RemoveDir FilePath
|
|
|
|
| Replace FilePath Text Text Text
|
|
|
|
| Binary FilePath ByteString ByteString
|
|
|
|
| Pref Text Text Text
|
|
|
|
|
|
|
|
splitChange :: P.Change -> Either P.Hunk Change
|
|
|
|
splitChange = f
|
|
|
|
where
|
|
|
|
text = decodeUtf8
|
|
|
|
path = T.unpack . text
|
|
|
|
f (P.EditFile h) = Left h
|
|
|
|
f (P.AddFile p) = Right $ AddFile (path p)
|
|
|
|
f (P.AddDir p) = Right $ AddDir (path p)
|
|
|
|
f (P.Move old new) = Right $ Move (path old) (path new)
|
|
|
|
f (P.RemoveFile p) = Right $ RemoveFile (path p)
|
|
|
|
f (P.RemoveDir p) = Right $ RemoveDir (path p)
|
|
|
|
f (P.Replace p r old new) = Right $ Replace (path p) (text r) (text old) (text new)
|
|
|
|
f (P.Binary p old new) = Right $ Binary (path p) old new
|
|
|
|
f (P.Pref pref old new) = Right $ Pref (text pref) (text old) (text new)
|
|
|
|
|
2018-07-09 19:12:11 +00:00
|
|
|
-- | Group hunks by filename, assuming all the hunks for a given file are
|
|
|
|
-- placed together in the patch file, and in increasing line number order.
|
|
|
|
groupHunksByFile
|
2019-10-31 10:11:13 +00:00
|
|
|
:: NonEmpty (P.Hunk)
|
|
|
|
-> NonEmpty (ByteString, NonEmpty (Int, [ByteString], [ByteString]))
|
|
|
|
groupHunksByFile = groupWithExtract1 P.hunkFile rest
|
2018-07-09 19:12:11 +00:00
|
|
|
where
|
|
|
|
rest h = (P.hunkLine h, P.hunkRemove h, P.hunkAdd h)
|
|
|
|
|
|
|
|
-- | Find groups of consecutive sequences of removes and adds, and turn each
|
|
|
|
-- such group into a single hunk. This may not actually be necessary, because
|
|
|
|
-- the small consecutive hunks would be joined later anyway when adding context
|
|
|
|
-- lines, but I'm still doing this here for consistency. In the "Vervis.Git"
|
|
|
|
-- module, the hunks are joined like this too.
|
|
|
|
joinHunks
|
|
|
|
:: NonEmpty (Int, [ByteString], [ByteString])
|
|
|
|
-> NonEmpty (Bool, Int, Hunk)
|
|
|
|
joinHunks =
|
2019-10-31 10:11:13 +00:00
|
|
|
NE.map (mkHunk . second groupPairs) .
|
2018-07-09 19:12:11 +00:00
|
|
|
groupMapBy1 consecutive lineNumber lines
|
|
|
|
where
|
|
|
|
consecutive (n1, r1, _) (n2, _, _) = n1 + length r1 == n2
|
|
|
|
lineNumber (n, _, _) = n
|
|
|
|
lines (_, rs, as) = (map decodeUtf8 rs, map decodeUtf8 as)
|
|
|
|
mkHunk (line, (adds, pairs, rems)) = (False, line, Hunk adds pairs rems)
|
|
|
|
|
2018-07-08 14:45:35 +00:00
|
|
|
-- | Read patch content, both metadata and the actual diff, from a given Darcs
|
|
|
|
-- repository. Preconditions:
|
|
|
|
--
|
2018-07-10 14:02:30 +00:00
|
|
|
-- * The repo's existence has been verified against the DB
|
|
|
|
-- * The repo dir is assumed to exist. If it doesn't, an exception is thrown.
|
2018-07-08 14:45:35 +00:00
|
|
|
-- * The repository is assumed to be in a consistent state, all the expected
|
|
|
|
-- inventory files and patch files and so on are assumed to exist and have
|
|
|
|
-- the expected format. If not, an exception is thrown.
|
|
|
|
-- * The hash may or may not be found in the repo. If there's no patch in the
|
|
|
|
-- repo with the given hash, 'Nothing' is returned.
|
2020-05-24 09:17:49 +00:00
|
|
|
readPatch :: FilePath -> Text -> IO (Maybe DP.Patch)
|
2019-10-23 09:31:37 +00:00
|
|
|
readPatch path hash = handle $ runExceptT $ do
|
2018-07-08 14:45:35 +00:00
|
|
|
let pih = PatchInfoHash $ fst $ B16.decode $ encodeUtf8 hash
|
2019-10-23 09:31:37 +00:00
|
|
|
li <- ExceptT $ readLatestInventory path latestInventoryAllP
|
2018-07-08 14:45:35 +00:00
|
|
|
mp <- loop pih (liPatches li) (fst <$> liPrevTag li)
|
|
|
|
for mp $ \ (pi, pch) -> do
|
2019-10-31 10:11:13 +00:00
|
|
|
(_pir, changes) <-
|
2019-10-23 09:31:37 +00:00
|
|
|
ExceptT $ readCompressedPatch path pch (P.patch <* A.endOfInput)
|
|
|
|
(an, ae) <-
|
|
|
|
ExceptT . pure $ A.parseOnly (author <* A.endOfInput) $ piAuthor pi
|
2020-05-24 09:17:49 +00:00
|
|
|
return DP.Patch
|
2019-08-06 13:23:11 +00:00
|
|
|
{ patchWritten =
|
|
|
|
( Author
|
|
|
|
{ authorName = an
|
|
|
|
, authorEmail = ae
|
|
|
|
}
|
|
|
|
, piTime pi
|
|
|
|
)
|
|
|
|
, patchCommitted = Nothing
|
2018-07-08 14:45:35 +00:00
|
|
|
, patchTitle = piTitle pi
|
|
|
|
, patchDescription = fromMaybe "" $ piDescription pi
|
2018-07-09 19:12:11 +00:00
|
|
|
, patchDiff =
|
2019-10-31 10:11:13 +00:00
|
|
|
let (befores, pairs, afters) = groupEithers $ map splitChange changes
|
|
|
|
befores' = mkedit befores
|
|
|
|
pairs' = map (bimap arrangeHunks mkedit) pairs
|
|
|
|
afters' = arrangeHunks <$> nonEmpty afters
|
|
|
|
in befores' ++ concatMap (NE.toList . uncurry (<>)) pairs' ++ maybe [] NE.toList afters'
|
2018-07-08 14:45:35 +00:00
|
|
|
}
|
|
|
|
where
|
2019-10-23 09:31:37 +00:00
|
|
|
handle a = do
|
|
|
|
r <- a
|
|
|
|
case r of
|
|
|
|
Left e -> fail $ "readPatch failed: " ++ e
|
|
|
|
Right mp -> return mp
|
2018-07-08 14:45:35 +00:00
|
|
|
lookup' pih ps = case F.find (\ (_pi, pih', _pch) -> pih' == pih) ps of
|
|
|
|
Nothing -> Nothing
|
|
|
|
Just (pi, _pih, pch) -> Just (pi, pch)
|
|
|
|
loop pih ps mih = case lookup' pih ps of
|
|
|
|
Just p -> return $ Just p
|
|
|
|
Nothing -> case mih of
|
|
|
|
Nothing -> return Nothing
|
|
|
|
Just ih -> do
|
2019-10-23 09:31:37 +00:00
|
|
|
i <- ExceptT $ readCompressedInventory path ih earlyInventoryAllP
|
2018-07-08 14:45:35 +00:00
|
|
|
case i of
|
|
|
|
Left ei -> loop pih (eiPatches ei) Nothing
|
|
|
|
Right mi -> loop pih (miPatches mi) (Just $ miPrevious mi)
|
|
|
|
email = maybe (fail "invalid email") pure . emailAddress . encodeUtf8
|
|
|
|
author = (,)
|
2018-07-10 15:26:16 +00:00
|
|
|
<$> (T.stripEnd <$> A.takeWhile1 (/= '<'))
|
|
|
|
<* A.skip (== '<')
|
2018-07-08 14:45:35 +00:00
|
|
|
<*> (A.takeWhile1 (/= '>') >>= email)
|
|
|
|
<* A.skip (== '>')
|
2019-10-31 10:11:13 +00:00
|
|
|
arrangeHunks = NE.map (mkhunk . second joinHunks) . groupHunksByFile
|
|
|
|
where
|
|
|
|
mkhunk (file, hunks) =
|
|
|
|
EditTextFile (T.unpack $ decodeUtf8 file) V.empty hunks 0 0
|
|
|
|
mkedit = fmap mkedit'
|
|
|
|
where
|
|
|
|
mkedit' (AddFile fp) = AddTextFile fp 0 []
|
|
|
|
mkedit' (AddDir fp) = AddTextFile fp 0 []
|
|
|
|
mkedit' (Move old new) = MoveFile old 0 new 0
|
|
|
|
mkedit' (RemoveFile fp) = RemoveTextFile fp 0 []
|
|
|
|
mkedit' (RemoveDir fp) = RemoveTextFile fp 0 []
|
|
|
|
mkedit' (Replace fp regex old new) = AddTextFile "Replace" 0 [T.concat ["replace ", T.pack fp, " ", regex, " ", old, " ", new]]
|
|
|
|
mkedit' (Binary fp old new) = EditBinaryFile fp (fromIntegral $ B.length old) 0 (fromIntegral $ B.length new) 0
|
|
|
|
mkedit' (Pref pref old new) = AddTextFile "Pref" 0 [T.concat ["changepref ", pref, " ", old, " ", new]]
|
2019-10-07 14:05:52 +00:00
|
|
|
|
|
|
|
writePostApplyHooks :: WorkerDB ()
|
|
|
|
writePostApplyHooks = do
|
|
|
|
hook <- asksSite $ appPostApplyHookFile . appSettings
|
2019-10-20 09:19:49 +00:00
|
|
|
authority <- asksSite $ renderAuthority . siteInstanceHost
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
repos <- selectKeysList [RepoVcs ==. VCSDarcs] []
|
|
|
|
for_ repos $ \ repoID -> do
|
|
|
|
repoHash <- encodeKeyHashid repoID
|
|
|
|
path <- askRepoDir repoHash
|
2019-10-20 09:19:49 +00:00
|
|
|
liftIO $
|
Switch to new actor layout
This is such a huge patch, it's probably impossible to tell what it does by
looking at the code. One thing is clear: It changes *everything* :P so here's
an overview:
- There are now 5 types of actors, each having its own top-level route
- So projects, repos, etc. are no longer "under" sharers
- Actor routes are now based on their KeyHashid, there are no "idents" anymore,
i.e. URLs look random and don't contain user or repo names
- No sharers anymore; people and groups are distinct entities not sharing a
common namespace or anything like that
- Project has been renamed to Deck and it simply means a ticket tracker; repos
are no longer "under" projects
- In addition to Person, Group, Repo and Deck, there's a new actor type Loom,
which is a patch tracker; i.e. Repo actors don't manage MRs anymore
- All C2S and S2S is temporarily disabled, because huge changes to the whole
code are required and I'll do them gradually in the next patches
- Since form-based actions are implemented using C2S, they're disabled as well,
so Vervis is now essentially read-only
- Some views have been temporarily removed, e.g. repo history and commit view
- A huge set of DB migrations has been added to adapt the DB to these changes;
I haven't tested them yet on a read DB so there may be errors there; I'll fix
them in the next patches if I find any (probably going to test on the main
instance where Vervis itself is hosted...)
- Some modules got tech upgrades, e.g. LocalActor became a higher-kinded type
and a similar pattern is probably relevant for several other types
- There's an 'Actor' entity in the DB schema now, and all 5 actor types use it
for common things like inbox and outbox
- Although inbox and outbox are used only by Actor, so essentially could be
removed, I haven't removed them; that's because I wonder if at some point
users can have a tree of inboxes much like in email; I don't have an excuse
for Outbox, but anyway, leaving them as is for now
- Workflows, roles and collaborators are partially removed/unused until I
figure out a sane federated way to provide these features
- Since repo routes don't contain a "sharer" anymore, SSH URIs are now simpler,
they already look like user@host/repo regardless of who "controls" that repo
2022-08-15 13:57:42 +00:00
|
|
|
writeDefaultsFile path hook authority (keyHashidText repoHash)
|
2022-06-25 19:59:26 +00:00
|
|
|
|
2022-09-24 21:15:40 +00:00
|
|
|
canApplyDarcsPatch repoPath patch = do
|
|
|
|
let input = BL.fromStrict $ TE.encodeUtf8 patch
|
|
|
|
exitCode <- runProcess $ setStdin (byteStringInput input) $ proc "darcs" ["apply", "--all", "--no-allow-conflicts", "--dry-run", "--repodir='" ++ repoPath ++ "'"]
|
|
|
|
return $ exitCode == ExitSuccess
|
|
|
|
|
2022-09-24 09:04:10 +00:00
|
|
|
applyDarcsPatch repoPath patch = do
|
2022-06-25 19:59:26 +00:00
|
|
|
let input = BL.fromStrict $ TE.encodeUtf8 patch
|
2022-09-24 09:04:10 +00:00
|
|
|
runProcessE "darcs apply" $ setStdin (byteStringInput input) $ proc "darcs" ["apply", "--all", "--no-allow-conflicts", "--repodir='" ++ repoPath ++ "'"]
|