summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-15 18:11:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-15 18:19:36 -0400
commit95d2391f58ae240e7100f0d5488dd7246f71f3bb (patch)
treef33f21904ae7be4d40b70bab1e2a68fd4eef5526 /Command
parentb7e0d39abbc9a09c21c6f0103ad6c9f4547f81fe (diff)
more partial function removal
Left a few Prelude.head's in where it was checked not null and too hard to remove, etc.
Diffstat (limited to 'Command')
-rw-r--r--Command/InitRemote.hs25
-rw-r--r--Command/Map.hs2
-rw-r--r--Command/Migrate.hs2
-rw-r--r--Command/Status.hs2
-rw-r--r--Command/Sync.hs4
-rw-r--r--Command/Uninit.hs2
-rw-r--r--Command/Unused.hs10
7 files changed, 21 insertions, 26 deletions
diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs
index 600e17eb8..1e6bc2ef1 100644
--- a/Command/InitRemote.hs
+++ b/Command/InitRemote.hs
@@ -25,9 +25,13 @@ seek :: [CommandSeek]
seek = [withWords start]
start :: [String] -> CommandStart
-start ws = do
- when (null ws) needname
-
+start [] = do
+ names <- remoteNames
+ error $ "Specify a name for the remote. " ++
+ if null names
+ then ""
+ else "Either a new name, or one of these existing special remotes: " ++ join " " names
+start (name:ws) = do
(u, c) <- findByName name
let fullconfig = config `M.union` c
t <- findType fullconfig
@@ -36,15 +40,7 @@ start ws = do
next $ perform t u $ M.union config c
where
- name = head ws
- config = Logs.Remote.keyValToConfig $ tail ws
- needname = do
- let err s = error $ "Specify a name for the remote. " ++ s
- names <- remoteNames
- if null names
- then err ""
- else err $ "Either a new name, or one of these existing special remotes: " ++ join " " names
-
+ config = Logs.Remote.keyValToConfig ws
perform :: R.RemoteType Annex -> UUID -> R.RemoteConfig -> CommandPerform
perform t u c = do
@@ -67,11 +63,8 @@ findByName name = do
return (uuid, M.insert nameKey name M.empty)
findByName' :: String -> M.Map UUID R.RemoteConfig -> Maybe (UUID, R.RemoteConfig)
-findByName' n m
- | null matches = Nothing
- | otherwise = Just $ head matches
+findByName' n = headMaybe . filter (matching . snd) . M.toList
where
- matches = filter (matching . snd) $ M.toList m
matching c = case M.lookup nameKey c of
Nothing -> False
Just n'
diff --git a/Command/Map.hs b/Command/Map.hs
index 15ca5e149..da129c8f6 100644
--- a/Command/Map.hs
+++ b/Command/Map.hs
@@ -73,7 +73,7 @@ hostname r
| otherwise = "localhost"
basehostname :: Git.Repo -> String
-basehostname r = head $ split "." $ hostname r
+basehostname r = Prelude.head $ split "." $ hostname r
{- A name to display for a repo. Uses the name from uuid.log if available,
- or the remote name if not. -}
diff --git a/Command/Migrate.hs b/Command/Migrate.hs
index 30288fc16..8778743ff 100644
--- a/Command/Migrate.hs
+++ b/Command/Migrate.hs
@@ -31,7 +31,7 @@ start b file (key, oldbackend) = do
next $ perform file key newbackend
else stop
where
- choosebackend Nothing = head <$> Backend.orderedList
+ choosebackend Nothing = Prelude.head <$> Backend.orderedList
choosebackend (Just backend) = return backend
{- Checks if a key is upgradable to a newer representation. -}
diff --git a/Command/Status.hs b/Command/Status.hs
index 09da41987..736d897ef 100644
--- a/Command/Status.hs
+++ b/Command/Status.hs
@@ -116,7 +116,7 @@ remote_list level desc = stat n $ nojson $ lift $ do
us <- M.keys <$> (M.union <$> uuidMap <*> remoteMap)
rs <- fst <$> trustPartition level us
s <- prettyPrintUUIDs n rs
- return $ if null s then "0" else show (length rs) ++ "\n" ++ init s
+ return $ if null s then "0" else show (length rs) ++ "\n" ++ beginning s
where
n = desc ++ " repositories"
diff --git a/Command/Sync.hs b/Command/Sync.hs
index a25bcad8c..36c4eeef0 100644
--- a/Command/Sync.hs
+++ b/Command/Sync.hs
@@ -12,6 +12,8 @@ import Command
import qualified Annex.Branch
import qualified Git.Command
import qualified Git.Config
+import qualified Git.Ref
+import qualified Git
import qualified Data.ByteString.Lazy.Char8 as L
@@ -61,7 +63,7 @@ defaultRemote = do
fromRepo $ Git.Config.get ("branch." ++ branch ++ ".remote") "origin"
currentBranch :: Annex String
-currentBranch = last . split "/" . L.unpack . head . L.lines <$>
+currentBranch = Git.Ref.describe . Git.Ref . firstLine . L.unpack <$>
inRepo (Git.Command.pipeRead [Param "symbolic-ref", Param "HEAD"])
checkRemote :: String -> Annex ()
diff --git a/Command/Uninit.hs b/Command/Uninit.hs
index fc6f0cc27..21ad4c7df 100644
--- a/Command/Uninit.hs
+++ b/Command/Uninit.hs
@@ -29,7 +29,7 @@ check = do
when (b == Annex.Branch.name) $ error $
"cannot uninit when the " ++ show b ++ " branch is checked out"
where
- current_branch = Git.Ref . head . lines . B.unpack <$> revhead
+ current_branch = Git.Ref . Prelude.head . lines . B.unpack <$> revhead
revhead = inRepo $ Git.Command.pipeRead
[Params "rev-parse --abbrev-ref HEAD"]
diff --git a/Command/Unused.hs b/Command/Unused.hs
index 8a70ff335..ef398b01e 100644
--- a/Command/Unused.hs
+++ b/Command/Unused.hs
@@ -154,13 +154,13 @@ excludeReferenced l = do
(S.fromList l)
where
-- Skip the git-annex branches, and get all other unique refs.
- refs = map (Git.Ref . last) .
- nubBy cmpheads .
+ refs = map (Git.Ref . snd) .
+ nubBy uniqref .
filter ourbranches .
- map words . lines . L.unpack
- cmpheads a b = head a == head b
+ map (separate (== ' ')) . lines . L.unpack
+ uniqref (a, _) (b, _) = a == b
ourbranchend = '/' : show Annex.Branch.name
- ourbranches ws = not $ ourbranchend `isSuffixOf` last ws
+ ourbranches (_, b) = not $ ourbranchend `isSuffixOf` b
removewith [] s = return $ S.toList s
removewith (a:as) s
| s == S.empty = return [] -- optimisation