Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ jobs:
echo "package notmuch" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
cat >> cabal.project <<EOF
flags: +demos
EOF
if $HEADHACKAGE; then
echo "allow-newer: $($HCPKG list --simple-output | sed -E 's/([a-zA-Z-]+)-[0-9.]+/*:\1,/g')" >> cabal.project
Expand Down
2 changes: 2 additions & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
raw-project
flags: +demos
20 changes: 11 additions & 9 deletions notmuch.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ library
, time
, text

build-tools:
c2hs >= 0.19.1
build-tool-depends:
c2hs:c2hs >= 0.19.1

extra-libraries:
notmuch
Expand All @@ -98,17 +98,24 @@ executable hs-notmuch-files
if !flag(demos)
buildable: False
hs-source-dirs: tools
ghc-options: -Wall
main-is: Files.hs
build-depends:
, notmuch

executable hs-notmuch-dbinfo
import: common
if !flag(demos)
buildable: False
hs-source-dirs: tools
main-is: DbInfo.hs
build-depends:
, notmuch

executable hs-notmuch-tag-message
import: common
if !flag(demos)
buildable: False
hs-source-dirs: tools
ghc-options: -Wall
main-is: TagMessage.hs
build-depends:
, bytestring
Expand All @@ -119,10 +126,8 @@ executable hs-notmuch-tag-count
if !flag(demos)
buildable: False
hs-source-dirs: tools
ghc-options: -Wall
main-is: TagCount.hs
build-depends:
, bytestring
, containers
, notmuch

Expand All @@ -131,18 +136,15 @@ executable hs-notmuch-tag-set
if !flag(demos)
buildable: False
hs-source-dirs: tools
ghc-options: -Wall
main-is: TagSet.hs
build-depends:
, bytestring
, notmuch

executable hs-notmuch-index-file
import: common
if !flag(demos)
buildable: False
hs-source-dirs: tools
ghc-options: -Wall
main-is: IndexFile.hs
build-depends:
, notmuch
17 changes: 14 additions & 3 deletions src/Notmuch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module Notmuch
, databaseOpenReadOnly
, databasePath
, databaseVersion
, databaseRevision
, Database
-- ** Database modes
, Mode
Expand Down Expand Up @@ -146,6 +147,7 @@ import Control.Exception (bracket)
import Control.Monad.Except (MonadError(..))
import Control.Monad.IO.Class (MonadIO(..))
import Data.Foldable (traverse_)
import Foreign.C.Types (CULong)
import GHC.Generics (Generic)

import Control.DeepSeq (NFData)
Expand Down Expand Up @@ -240,6 +242,17 @@ databaseOpenReadOnly = database_open
databaseVersion :: MonadIO m => Database a -> m Int
databaseVersion = liftIO . database_get_version

-- | Get the revision and UUID of the database.
--
-- The revision number increases monotonically with each commit to
-- the database (although rollover is possible). The "UUID" is an
-- __opaque__ string that persists until e.g. database compaction.
-- Revision numbers are only comparable where the UUID strings are
-- equal.
--
databaseRevision :: MonadIO m => Database a -> m (CULong, String)
databaseRevision = liftIO . database_get_revision

-- | Look for a particular message in the database.
findMessage
:: (AsNotmuchError e, MonadError e m, MonadIO m)
Expand Down Expand Up @@ -322,9 +335,7 @@ messageRemoveTag :: (MonadIO m) => Tag -> Message n RW -> m ()
messageRemoveTag tag msg = liftIO $ message_remove_tag msg tag

-- | Returns only messages in a thread which are not replies to other messages in the thread.
threadToplevelMessages
:: (AsNotmuchError e, MonadError e m, MonadIO m)
=> Thread a -> m [Message 0 a]
threadToplevelMessages :: (MonadIO m) => Thread a -> m [Message 0 a]
threadToplevelMessages = thread_get_toplevel_messages

-- | /O(1)/ Date of the newest message in a 'Thread'.
Expand Down
8 changes: 8 additions & 0 deletions src/Notmuch/Binding.chs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ database_get_version :: Database a -> IO Int
database_get_version db =
fromIntegral <$> withDatabase db {#call unsafe database_get_version #}

database_get_revision :: Database a -> IO (CULong, String)
database_get_revision db =
withDatabase db $ \db' ->
alloca $ \uuidPtr -> do
rev <- {#call unsafe database_get_revision #} db' uuidPtr
uuid <- peekCString =<< peek uuidPtr
pure (rev, uuid)

-- | Index a file with the default indexing options.
-- (This binding does not yet provide a way to change
-- the indexing options.) Returns the indexed message.
Expand Down
47 changes: 47 additions & 0 deletions tools/DbInfo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- This file is part of hs-notmuch - Haskell Notmuch binding
-- Copyright (C) 2022 Yikai Zhao
--
-- hs-notmuch is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

{-

Print version and revision info for a database.

-}

{-# LANGUAGE LambdaCase #-}

import Control.Monad.Except (runExceptT)
import System.Environment (getArgs)
import System.Exit (die)

import Notmuch


main :: IO ()
main = getArgs >>= \case
[dbDir] -> go dbDir
_ -> putStrLn "usage: hs-notmuch-dbinfo DB-DIR"

go :: String -> IO ()
go dbDir = do
(version, (revision, uuid)) <- runExceptT (
do
db <- databaseOpenReadOnly dbDir
(,) <$> databaseVersion db <*> databaseRevision db
) >>= either (die . (show :: Status -> String)) pure
putStr "Path: " *> putStrLn dbDir
putStr "Version: " *> print version
putStr "Revision: " *> print revision
putStr "UUID: " *> putStrLn uuid
3 changes: 2 additions & 1 deletion tools/IndexFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Index or remove the given file.

{-# LANGUAGE LambdaCase #-}

import Control.Monad.Except ((>=>), runExceptT)
import Control.Monad ((>=>))
import Control.Monad.Except (runExceptT)
import System.Environment (getArgs)
import System.Exit (die)

Expand Down
Loading