diff --git a/src/Vervis/Darcs.hs b/src/Vervis/Darcs.hs index 0d7b0d9..251a2bb 100644 --- a/src/Vervis/Darcs.hs +++ b/src/Vervis/Darcs.hs @@ -18,6 +18,7 @@ module Vervis.Darcs , readWikiView , readChangesView , lastChange + , readPatch ) where @@ -55,6 +56,7 @@ import Data.Text.UTF8.Local (decodeStrict) import Data.Time.Clock.Local () import Vervis.Changes import Vervis.Foundation (Widget) +import Vervis.Patch import Vervis.Readme import Vervis.SourceTree import Vervis.Wiki (WikiView (..)) @@ -218,3 +220,41 @@ lastChange path now = fmap maybeRight $ runExceptT $ do intervalToEventTime $ FriendlyConvert $ now `diffUTCTime` piTime pi + +-- TODO +readPatch :: FilePath -> Text -> IO (Maybe Patch) +readPatch path hash = error "Not implemented" + -- I'm not sure what's the fastest way to find a patch file given its info + -- hash, maybe Darcs keeps some cache or something. But assuming there are + -- no tricks like that, here's an idea how to grab the patch: + -- + -- (1) Start going over the whole inventory, whose order is from latest to + -- oldest, looking for a patch with the given hash. + -- (2) Once found, determine the patch filename from its size and content + -- hash + -- (3) Run the patch parser on that file, through a zlib decompressor + -- though (check how I did that for the inventories parser) + -- + -- TODO idea: Use hints to speed up finding the patch! In the repo history + -- log page, embed hints into the hyperlinks to the patches, and in the + -- patch page handler, use the hint to figure out the patch location. + -- Actually, since the inventory file contains patch content hashes, I can + -- use that as a hint and skip the whole step of looking for the patch! + -- + -- TODO maybe start by finding the patch hash in patch_ids and use the + -- position as a hint to its location in the inventories + -- + -- TODO maybe I can figure out from darcs source code how a given patch + -- hash is found? Just in case there's a faster way + -- + -- TODO find out what's the index and patch_index files under _darcs and + -- maybe other files there, possibly there's a way to patch the info hash + -- with the content hash. + -- + -- UPDATE: I read about index and patch_index, looks like they won't help. + -- But possibly the global cache system will? However interesting note: + -- Vervis on my laptop has a patch_index, but on the server it doesn't. + -- Probably because `darcs log` never runs on the server since I parse + -- patches manually. If I end up using the patch index for something, it + -- may be a good idea to trigger its generation, so that it's available + -- when people browser repo pages. diff --git a/src/Vervis/Handler/Repo.hs b/src/Vervis/Handler/Repo.hs index 14f3952..f83a2f2 100644 --- a/src/Vervis/Handler/Repo.hs +++ b/src/Vervis/Handler/Repo.hs @@ -263,7 +263,7 @@ getRepoPatchR :: ShrIdent -> RpIdent -> Text -> Handler Html getRepoPatchR shr rp ref = do repository <- runDB $ selectRepo shr rp case repoVcs repository of - VCSDarcs -> error "Not implemented yet" -- getDarcsPatch shr rp ref + VCSDarcs -> getDarcsPatch shr rp ref VCSGit -> getGitPatch shr rp ref getRepoDevsR :: ShrIdent -> RpIdent -> Handler Html diff --git a/src/Vervis/Handler/Repo/Darcs.hs b/src/Vervis/Handler/Repo/Darcs.hs index a45f80f..b2f6e29 100644 --- a/src/Vervis/Handler/Repo/Darcs.hs +++ b/src/Vervis/Handler/Repo/Darcs.hs @@ -18,6 +18,7 @@ module Vervis.Handler.Repo.Darcs , getDarcsRepoHeadChanges , getDarcsRepoChanges , getDarcsDownloadR + , getDarcsPatch ) where @@ -106,3 +107,6 @@ getDarcsDownloadR shar repo dir = do if exists then sendFile typeOctet filePath else notFound + +getDarcsPatch :: ShrIdent -> RpIdent -> Text -> Handler Html +getDarcsPatch shr rp ref = error "Not implemented"