avoid partial function, and parse git-ref output better

It's possible that a ref name might contain a space, this properly
preserves the space.
This commit is contained in:
Joey Hess 2011-12-15 16:58:04 -04:00
parent eb132a854e
commit fbc3d32f7d

View file

@ -41,8 +41,8 @@ sha branch repo = process . L.unpack <$> showref repo
matching :: Ref -> Repo -> IO [(Ref, Branch)] matching :: Ref -> Repo -> IO [(Ref, Branch)]
matching ref repo = do matching ref repo = do
r <- pipeRead [Param "show-ref", Param $ show ref] repo r <- pipeRead [Param "show-ref", Param $ show ref] repo
return $ nubBy uref $ map (gen . words . L.unpack) (L.lines r) return $ nubBy uniqref $ map (gen . L.unpack) (L.lines r)
where where
gen l = (Ref $ head l, Ref $ last l) uniqref (a, _) (b, _) = a == b
uref (a, _) (b, _) = a == b gen l = let (r, b) = separate (== ' ') l in
(Ref r, Ref b)