Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cabal
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
Cabal
Commits
5caa02f2
Commit
5caa02f2
authored
12 years ago
by
Unused old account for @chreekat
Browse files
Options
Downloads
Patches
Plain Diff
Separate IO out of 'cabal init' author heuristics.
parent
81cf2e4d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cabal-install/Distribution/Client/Init/Heuristics.hs
+56
-42
56 additions, 42 deletions
cabal-install/Distribution/Client/Init/Heuristics.hs
with
56 additions
and
42 deletions
cabal-install/Distribution/Client/Init/Heuristics.hs
+
56
−
42
View file @
5caa02f2
...
...
@@ -31,12 +31,12 @@ import Distribution.Simple.Utils
import
Distribution.Client.Types
(
packageDescription
,
SourcePackageDb
(
..
)
)
import
Control.Applicative
(
pure
,
(
<$>
),
(
<*>
)
)
import
Control.Monad
(
liftM
,
join
)
import
Control.Monad
(
liftM
)
import
Data.Char
(
isUpper
,
isLower
,
isSpace
)
import
Data.Either
(
partitionEithers
)
import
Data.List
(
isPrefixOf
)
import
Data.Maybe
(
mapMaybe
,
catMaybes
,
maybeToList
)
import
Data.Monoid
(
mempty
,
mappend
,
mconcat
)
import
Data.Monoid
(
mempty
,
mconcat
)
import
qualified
Data.Set
as
Set
(
fromList
,
toList
)
import
System.Directory
(
getDirectoryContents
,
doesDirectoryExist
,
doesFileExist
,
getHomeDirectory
,
canonicalizePath
)
...
...
@@ -166,56 +166,60 @@ neededBuildPrograms entries =
--
-- Darcs has preference, for tradition's sake.
guessAuthorNameMail
::
IO
(
Flag
String
,
Flag
String
)
guessAuthorNameMail
=
fmap
mconcat
$
sequence
[
emailEnv
,
gitCfg
Global
,
darcsGlobal
,
gitCfg
Local
,
darcsRepo
,
gitEnv
,
darcsEnv
]
guessAuthorNameMail
=
fmap
authorGuessPure
authorGuessIO
-- Ordered in increasing preference, since Flag-as-monoid is identical to
-- Last.
authorGuessPure
::
AuthorGuessIO
->
AuthorGuess
authorGuessPure
(
AuthorGuessIO
env
darcsLocalF
darcsGlobalF
gitLocal
gitGlobal
)
=
mconcat
[
emailEnv
env
,
gitGlobal
,
darcsCfg
darcsGlobalF
,
gitLocal
,
darcsCfg
darcsLocalF
,
gitEnv
env
,
darcsEnv
env
]
authorGuessIO
::
IO
AuthorGuessIO
authorGuessIO
=
AuthorGuessIO
<$>
getEnvironment
<*>
(
maybeReadFile
$
"_darcs"
</>
"prefs"
</>
"author"
)
<*>
(
maybeReadFile
=<<
liftM
(
</>
(
".darcs"
</>
"author"
))
getHomeDirectory
)
<*>
gitCfg
Local
<*>
gitCfg
Global
-- Types and functions used for guessing the author are now defined:
type
AuthorGuess
=
(
Flag
String
,
Flag
String
)
type
Enviro
=
[(
String
,
String
)]
data
GitLoc
=
Local
|
Global
darcsEnv
::
IO
AuthorGuess
darcsEnv
=
fmap
extractDarcs
getEnvironment
where
extractDarcs
=
maybe
mempty
nameAndMail
.
lookup
"DARCS_EMAIL"
gitEnv
::
IO
AuthorGuess
gitEnv
=
do
env
<-
getEnvironment
let
name
=
toFlag
"GIT_AUTHOR_NAME"
env
email
=
toFlag
"GIT_AUTHOR_EMAIL"
env
return
(
name
,
email
)
where
toFlag
k
ls
=
maybe
mempty
Flag
$
lookup
k
ls
darcsRepo
::
IO
AuthorGuess
darcsRepo
=
readFromFile
authorRepoFile
where
authorRepoFile
=
"_darcs"
</>
"prefs"
</>
"author"
darcsGlobal
=
join
.
fmap
readFromFile
$
globalCfg
data
AuthorGuessIO
=
AuthorGuessIO
Enviro
-- ^ Environment lookup table
(
Maybe
String
)
-- ^ Contents of local darcs author info
(
Maybe
String
)
-- ^ Contents of global darcs author info
AuthorGuess
-- ^ Git config --local
AuthorGuess
-- ^ Git config --global
darcsEnv
::
Enviro
->
AuthorGuess
darcsEnv
=
maybe
mempty
nameAndMail
.
lookup
"DARCS_EMAIL"
gitEnv
::
Enviro
->
AuthorGuess
gitEnv
env
=
(
name
,
email
)
where
globalCfg
=
fmap
(
</>
".darcs"
</>
"author"
)
getHomeDirectory
name
=
maybeFlag
"GIT_AUTHOR_NAME"
env
email
=
maybeFlag
"GIT_AUTHOR_EMAIL"
env
readFromFile
file
=
do
exists
<-
doesFileExist
file
if
exists
then
liftM
nameAndMail
(
readFile
file
)
else
return
mempty
darcsCfg
::
Maybe
String
->
AuthorGuess
darcsCfg
=
maybe
mempty
nameAndMail
emailEnv
::
IO
AuthorGuess
emailEnv
=
fmap
((,)
mempty
)
email
emailEnv
::
Enviro
->
AuthorGuess
emailEnv
env
=
(
mempty
,
email
)
where
email
=
maybe
mempty
Flag
<$>
lookup
"EMAIL"
<$>
getEnvironment
email
=
maybeFlag
"EMAIL"
env
gitCfg
::
GitLoc
->
IO
AuthorGuess
gitCfg
which
=
do
name
<-
gitVar
which
"user.name"
mail
<-
gitVar
which
"user.email"
...
...
@@ -238,6 +242,16 @@ gitConfigQuery which key =
Global
->
"--global"
trim'
(
a
,
b
,
c
)
=
(
a
,
trim
b
,
c
)
maybeFlag
::
String
->
Enviro
->
Flag
String
maybeFlag
k
=
maybe
mempty
Flag
.
lookup
k
maybeReadFile
::
String
->
IO
(
Maybe
String
)
maybeReadFile
f
=
do
exists
<-
doesFileExist
f
if
exists
then
fmap
Just
$
readFile
f
else
return
Nothing
-- |Get list of categories used in hackage. NOTE: Very slow, needs to be cached
knownCategories
::
SourcePackageDb
->
[
String
]
knownCategories
(
SourcePackageDb
sourcePkgIndex
_
)
=
nubSet
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment