Hello,
Eric Kow pointed out in #darcs that Reposity.lhs and DarcsRepo.lhs
have what appears to be duplicated code. Does anyone know or
remember why the two seemingly similar functions exist:
Repository.amInRepository
DarcsRepo.am_in_repository
Looking at the source code they are both identical up to calling a
helper function which is where they start to diverge:
amInRepository' :: FilePath -> IO (Either String FilePath)
amInRepository' dir =
do mr <- maybeIdentifyRepository "."
case mr of
Right _ -> return (Right dir)
Left _ ->
do cd <- getCurrentDirectory
setCurrentDirectory ".."
cd' <- getCurrentDirectory
if cd' /= cd
then amInRepository' $
reverse (takeWhile (/='/') $ reverse cd)///dir
else return (Left $
"You need to be in a repository
directory" ++
" to run this command.")
a_i_r :: FilePath -> IO (Either String FilePath)
a_i_r dir = do
air <- doesFileExist "_darcs/inventory" `mand`
doesDirectoryExist "_darcs/patches"
if air
then return $ Right dir
else do cd <- getCurrentDirectory
setCurrentDirectory ".."
cd' <- getCurrentDirectory
if cd' /= cd
then a_i_r $ reverse (takeWhile (/='/') $ reverse
cd)///dir
else return (Left $
"You need to be in a repository
directory" ++
" to run this command.")
mand :: IO Bool -> IO Bool -> IO Bool
a `mand` b = do isa <- a
if isa then b else return False
The only real difference that I see is that maybeIdentifyRepository
is more general in that it checks more cases and looks for more
things. On a side note, the definition of mand should be replaced by
the more idiomatic mand = liftM2 (&&).
Is it possible that this code is part of some rewrite that is in
progress? If it's just duplication, then I suspect we want to remove
the duplication and keep the version in Repository.lhs (but probably
change the identifiers to match the bulk of the darcs source).
Thanks,
Jason
_______________________________________________
darcs-devel mailing list
[email protected]
http://www.abridgegame.org/cgi-bin/mailman/listinfo/darcs-devel