mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-03-20 15:14:54 +09:00
Minimal pagination for git and darcs change log
This commit is contained in:
parent
17c4ff3d23
commit
b2f5b20184
12 changed files with 223 additions and 77 deletions
30
src/Data/Either/Local.hs
Normal file
30
src/Data/Either/Local.hs
Normal file
|
@ -0,0 +1,30 @@
|
|||
{- 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 Data.Either.Local
|
||||
( maybeRight
|
||||
, maybeLeft
|
||||
)
|
||||
where
|
||||
|
||||
import Prelude
|
||||
|
||||
maybeRight :: Either a b -> Maybe b
|
||||
maybeRight (Left _) = Nothing
|
||||
maybeRight (Right b) = Just b
|
||||
|
||||
maybeLeft :: Either a b -> Maybe a
|
||||
maybeLeft (Left a) = Just a
|
||||
maybeLeft (Right _) = Nothing
|
|
@ -21,6 +21,9 @@ module Data.Git.Local
|
|||
, TreeRows
|
||||
, PathView (..)
|
||||
, viewPath
|
||||
-- * View refs
|
||||
, listBranches
|
||||
, listTags
|
||||
)
|
||||
where
|
||||
|
||||
|
@ -31,6 +34,7 @@ import Data.Byteable (toBytes)
|
|||
import Data.Git
|
||||
import Data.Git.Harder
|
||||
import Data.Git.Types (GitTime (..))
|
||||
import Data.Set (Set)
|
||||
import Data.Text (Text)
|
||||
import Data.Text.Encoding (decodeUtf8With)
|
||||
import Data.Text.Encoding.Error (lenientDecode)
|
||||
|
@ -38,6 +42,8 @@ import System.Directory.Tree
|
|||
|
||||
import qualified Data.ByteString as B (ByteString, writeFile)
|
||||
import qualified Data.ByteString.Lazy as BL (ByteString)
|
||||
import qualified Data.Set as S (mapMonotonic)
|
||||
import qualified Data.Text as T (pack)
|
||||
|
||||
import Data.EventTime.Local
|
||||
import Data.Hourglass.Local ()
|
||||
|
@ -115,3 +121,9 @@ viewPath git root path = do
|
|||
case target of
|
||||
Left blob -> return $ BlobView nameT oid (blobGetContent blob)
|
||||
Right tree -> TreeView nameT oid <$> mkRows tree
|
||||
|
||||
listBranches :: Git -> IO (Set Text)
|
||||
listBranches git = S.mapMonotonic (T.pack . refNameRaw) <$> branchList git
|
||||
|
||||
listTags :: Git -> IO (Set Text)
|
||||
listTags git = S.mapMonotonic (T.pack . refNameRaw) <$> tagList git
|
||||
|
|
|
@ -156,4 +156,6 @@ paginate ps ns = do
|
|||
curr <- psCurrent ps
|
||||
let (offset, limit) = subseq (psPer ps) curr
|
||||
(total, items) <- psSelect ps offset limit
|
||||
return (items, navModel ns curr total)
|
||||
let (d, m) = total `divMod` psPer ps
|
||||
pages = if m == 0 then d else d + 1
|
||||
return (items, navModel ns curr pages)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue