fix all remaining -Wincomplete-uni-patterns warnings

A couple of these were probably actual bugs in edge cases. Most of the
changes I'm fine with. The fact that aeson's object returns sometihng
that we know will be an Object, but the type checker does not know is
kind of annoying.
This commit is contained in:
Joey Hess 2020-04-15 13:55:08 -04:00
parent 43a9808292
commit f85ca7dc80
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 41 additions and 27 deletions

View file

@ -119,8 +119,9 @@ perform c o k = case getSet o of
cleanup :: Key -> CommandCleanup cleanup :: Key -> CommandCleanup
cleanup k = do cleanup k = do
m <- getCurrentMetaData k m <- getCurrentMetaData k
let Object o = toJSON' (MetaDataFields m) case toJSON' (MetaDataFields m) of
maybeShowJSON $ AesonObject o Object o -> maybeShowJSON $ AesonObject o
_ -> noop
showLongNote $ unlines $ concatMap showmeta $ showLongNote $ unlines $ concatMap showmeta $
map unwrapmeta (fromMetaData m) map unwrapmeta (fromMetaData m)
return True return True

View file

@ -46,9 +46,9 @@ insertCostAfter [] _ = []
insertCostAfter l pos insertCostAfter l pos
| pos < 0 = costBetween 0 (l !! 0) : l | pos < 0 = costBetween 0 (l !! 0) : l
| nextpos > maxpos = l ++ [1 + l !! maxpos] | nextpos > maxpos = l ++ [1 + l !! maxpos]
| item == nextitem = | item == nextitem = case insertCostAfter lastsegment 0 of
let (_dup:new:l') = insertCostAfter lastsegment 0 (_dup:new:l') -> firstsegment ++ [costBetween item new, new] ++ l'
in firstsegment ++ [costBetween item new, new] ++ l' _ -> error "insertCostAfter internal error"
| otherwise = | otherwise =
firstsegment ++ [costBetween item nextitem ] ++ lastsegment firstsegment ++ [costBetween item nextitem ] ++ lastsegment
where where

View file

@ -84,14 +84,16 @@ doMerge hashhandle ch differ repo streamer = do
- a line suitable for update-index that union merges the two sides of the - a line suitable for update-index that union merges the two sides of the
- diff. -} - diff. -}
mergeFile :: S.ByteString -> RawFilePath -> HashObjectHandle -> CatFileHandle -> IO (Maybe L.ByteString) mergeFile :: S.ByteString -> RawFilePath -> HashObjectHandle -> CatFileHandle -> IO (Maybe L.ByteString)
mergeFile info file hashhandle h = case filter (`notElem` nullShas) [Ref asha, Ref bsha] of mergeFile info file hashhandle h = case S8.words info of
[] -> return Nothing [_colonmode, _bmode, asha, bsha, _status] ->
(sha:[]) -> use sha case filter (`notElem` nullShas) [Ref asha, Ref bsha] of
shas -> use [] -> return Nothing
=<< either return (hashBlob hashhandle . L8.unlines) (sha:[]) -> use sha
=<< calcMerge . zip shas <$> mapM getcontents shas shas -> use
=<< either return (hashBlob hashhandle . L8.unlines)
=<< calcMerge . zip shas <$> mapM getcontents shas
_ -> return Nothing
where where
[_colonmode, _bmode, asha, bsha, _status] = S8.words info
use sha = return $ Just $ use sha = return $ Just $
updateIndexLine sha TreeFile $ asTopFilePath file updateIndexLine sha TreeFile $ asTopFilePath file
-- Get file and split into lines to union merge. -- Get file and split into lines to union merge.

View file

@ -143,12 +143,12 @@ getTransfers' dirs wanted = do
transfers <- filter (wanted . transferKey) transfers <- filter (wanted . transferKey)
<$> mapMaybe parseTransferFile . concat <$> findfiles <$> mapMaybe parseTransferFile . concat <$> findfiles
infos <- mapM checkTransfer transfers infos <- mapM checkTransfer transfers
return $ map (\(t, Just i) -> (t, i)) $ return $ mapMaybe running $ zip transfers infos
filter running $ zip transfers infos
where where
findfiles = liftIO . mapM dirContentsRecursive findfiles = liftIO . mapM dirContentsRecursive
=<< mapM (fromRepo . transferDir) dirs =<< mapM (fromRepo . transferDir) dirs
running (_, i) = isJust i running (t, Just i) = Just (t, i)
running (_, Nothing) = Nothing
{- Number of bytes remaining to download from matching downloads that are in {- Number of bytes remaining to download from matching downloads that are in
- progress. -} - progress. -}

View file

@ -65,9 +65,11 @@ none :: JSONBuilder
none = id none = id
start :: String -> Maybe RawFilePath -> Maybe Key -> JSONBuilder start :: String -> Maybe RawFilePath -> Maybe Key -> JSONBuilder
start command file key _ = Just (o, False) start command file key _ = case j of
Object o -> Just (o, False)
_ -> Nothing
where where
Object o = toJSON' $ JSONActionItem j = toJSON' $ JSONActionItem
{ itemCommand = Just command { itemCommand = Just command
, itemKey = key , itemKey = key
, itemFile = fromRawFilePath <$> file , itemFile = fromRawFilePath <$> file
@ -102,18 +104,22 @@ note s (Just (o, e)) = Just (HM.insertWith combinelines "note" (toJSON' s) o, e)
combinelines new _old = new combinelines new _old = new
info :: String -> JSONBuilder info :: String -> JSONBuilder
info s _ = Just (o, True) info s _ = case j of
Object o -> Just (o, True)
_ -> Nothing
where where
Object o = object ["info" .= toJSON' s] j = object ["info" .= toJSON' s]
data JSONChunk v where data JSONChunk v where
AesonObject :: Object -> JSONChunk Object AesonObject :: Object -> JSONChunk Object
JSONChunk :: ToJSON' v => [(String, v)] -> JSONChunk [(String, v)] JSONChunk :: ToJSON' v => [(String, v)] -> JSONChunk [(String, v)]
add :: JSONChunk v -> JSONBuilder add :: JSONChunk v -> JSONBuilder
add v (Just (o, e)) = Just (HM.union o' o, e) add v (Just (o, e)) = case j of
Object o' -> Just (HM.union o' o, e)
_ -> Nothing
where where
Object o' = case v of j = case v of
AesonObject ao -> Object ao AesonObject ao -> Object ao
JSONChunk l -> object $ map mkPair l JSONChunk l -> object $ map mkPair l
mkPair (s, d) = (packString s, toJSON' d) mkPair (s, d) = (packString s, toJSON' d)
@ -125,12 +131,15 @@ complete v _ = add v (Just (HM.empty, True))
-- Show JSON formatted progress, including the current state of the JSON -- Show JSON formatted progress, including the current state of the JSON
-- object for the action being performed. -- object for the action being performed.
progress :: Maybe Object -> Maybe Integer -> BytesProcessed -> IO () progress :: Maybe Object -> Maybe Integer -> BytesProcessed -> IO ()
progress maction msize bytesprocessed = emit $ case maction of progress maction msize bytesprocessed =
Just action -> HM.insert "action" (Object action) o case j of
Nothing -> o Object o -> emit $ case maction of
Just action -> HM.insert "action" (Object action) o
Nothing -> o
_ -> return ()
where where
n = fromBytesProcessed bytesprocessed :: Integer n = fromBytesProcessed bytesprocessed :: Integer
Object o = case msize of j = case msize of
Just size -> object Just size -> object
[ "byte-progress" .= n [ "byte-progress" .= n
, "percent-progress" .= showPercentage 2 (percentage size n) , "percent-progress" .= showPercentage 2 (percentage size n)

View file

@ -223,8 +223,10 @@ storeBupUUID u buprepo = do
giveup "ssh failed" giveup "ssh failed"
else liftIO $ do else liftIO $ do
r' <- Git.Config.read r r' <- Git.Config.read r
let ConfigValue olduuid = Git.Config.get configkeyUUID mempty r' let noolduuid = case Git.Config.get configkeyUUID mempty r' of
when (S.null olduuid) $ ConfigValue olduuid -> S.null olduuid
NoConfigValue -> True
when noolduuid $
Git.Command.run Git.Command.run
[ Param "config" [ Param "config"
, Param "annex.uuid" , Param "annex.uuid"