Find git executable at run time
[git-darcs-import.git] / src / Darcs / Repository / Motd.lhs
blobbf1f6a122b4521c57175a39835411d300a7edcf3
1 % Copyright (C) 2002-2004 David Roundy
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
6 % any later version.
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
19 \begin{code}
20 module Darcs.Repository.Motd (get_motd, show_motd) where
21 import Control.Monad ( unless )
22 import Darcs.Flags ( DarcsFlag( Quiet ) )
23 import Darcs.External ( fetchFilePS, Cachable(..) )
24 import Darcs.Global ( darcsdir )
25 import qualified Data.ByteString as B (null, hPut, empty, ByteString)
26 import Darcs.Utils ( catchall )
27 import System.IO ( stdout )
28 \end{code}
30 \paragraph{motd}\label{motd}
31 The \verb!_darcs/prefs/motd! file may contain a ``message of the day''
32 which will be displayed to users who get or pull from the repository without the
33 \verb!--quiet! option.
35 \begin{code}
36 -- | Fetch and return the message of the day for a given repository.
37 get_motd :: String -> IO B.ByteString
38 get_motd repo = fetchFilePS (repo++"/"++darcsdir++"/prefs/motd") (MaxAge 600)
39 `catchall` return B.empty
41 -- | Display the message of the day for a given repository,
42 -- unless the 'Quiet' flag is passed in
43 show_motd :: [DarcsFlag] -> String -> IO ()
44 show_motd opts repo = unless (Quiet `elem` opts) $ do
45 motd <- get_motd repo
46 unless (B.null motd)
47 $ do B.hPut stdout motd
48 putStrLn "**********************"
49 \end{code}