Find git executable at run time
[git-darcs-import.git] / src / Darcs / Commands / ShowAuthors.lhs
blobc6312717cc98d66eda8497d52516ec0017fd9ad0
1 % Copyright (C) 2008 Eric Kow
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.
18 \subsubsection{darcs show authors}
19 \begin{code}
20 module Darcs.Commands.ShowAuthors ( show_authors ) where
22 import Data.List ( sort, group )
24 import Darcs.Arguments ( DarcsFlag(..), working_repo_dir )
25 import Darcs.Commands ( DarcsCommand(..), nodefaults )
26 import Darcs.External ( viewDoc )
27 import Darcs.Hopefully ( info )
28 import Darcs.Repository ( amInRepository, read_repo, withRepository, ($-) )
29 import Darcs.Patch.Info ( pi_author )
30 import Darcs.Ordered ( mapRL, concatRL )
31 import Printer ( text )
32 \end{code}
34 \options{show authors}
36 \haskell{show_authors_help}
38 \begin{code}
39 show_authors_description :: String
40 show_authors_description = "Show all authors in the repository."
41 \end{code}
43 \begin{code}
44 show_authors_help :: String
45 show_authors_help =
46 "The authors command writes a list of all patch authors in the repository to\n" ++
47 "standard output."
48 \end{code}
50 \begin{code}
51 show_authors :: DarcsCommand
52 show_authors = DarcsCommand {
53 command_name = "authors",
54 command_help = show_authors_help,
55 command_description = show_authors_description,
56 command_extra_args = 0,
57 command_extra_arg_help = [],
58 command_command = authors_cmd,
59 command_prereq = amInRepository,
60 command_get_arg_possibilities = return [],
61 command_argdefaults = nodefaults,
62 command_advanced_options = [],
63 command_basic_options = [working_repo_dir] }
65 authors_cmd :: [DarcsFlag] -> [String] -> IO ()
66 authors_cmd opts _ = withRepository opts $- \repository -> do
67 patches <- read_repo repository
68 let authors = mapRL process $ concatRL patches
69 viewDoc $ text $ unlines $
70 if Verbose `elem` opts
71 then authors
72 else reverse $ map shownames $ sort $
73 map (\s -> (length s,head s)) $ group $ sort authors
74 where
75 process = pi_author . info
76 shownames (n, a) = show n ++ "\t" ++ a
77 \end{code}