Go Haskell!
Functional programming is the new thing!
Why? you may ask...
Well, due to many thing most of which your little brain cant digest. But one thing even you could understand is that functionall languages produce cleaner code in fewer line. See for yourself:
send_to_them :: [DarcsFlag] -> String -> PatchSet -> IO ()
send_to_them opts their_name them =
let am_verbose = Verbose `elem` opts
am_quiet = Quiet `elem` opts
putVerbose s = when am_verbose $ putDocLn s
putInfo s = when (not am_quiet) $ putStrLn s
in
withRepoLock opts $ \repo -> do
us <- read_repo repo
case get_common_and_uncommon (us, them) of
(common, us', _) -> do
putVerbose $ text "We have the following patches to send:"
$$ (vcat $ map (human_friendly.fst) $ head us')
case us' of
[[]] -> do putInfo "No recorded local changes to send!"
exitWith ExitSuccess
_ -> return ()
s <- slurp_recorded repo
let our_ps = map (fromJust.snd) $ reverse $ head us'
with_selected_changes "send" opts s our_ps (Just $ length our_ps) $
\ (_,to_be_sent) -> do
print_dry_run_message_and_exit "send" opts to_be_sent
when (null to_be_sent) $ do
putInfo "You don't want to send any patches, and that's fine with me!"
exitWith ExitSuccess
bundle <- signString opts $ make_bundle opts
(fromJust $ apply_to_slurpy
(invert $ join_patches $ reverse $
map (fromJust.snd) $ head us') s)
common to_be_sent
if wants_output opts
then do fname <- get_output opts
case fname of
"-" -> putDoc bundle
_ -> writeDocBinFile fname bundle
else let
auto_subject [p] = "darcs patch: " ++ trim (patch_desc p) 57
auto_subject (p:ps) = "darcs patch: " ++ trim (patch_desc p) 43 ++
" (and " ++ show (length ps) ++ " more)"
auto_subject _ = error "Tried to get a name from empty patch list."
trim st n = if length st <= n then st
else take (n-3) st ++ "..."
patch_desc p = case patch2patchinfo p of
Just pinf -> just_name pinf
Nothing -> ""
in do
thetargets <- get_targets opts
from <- get_author opts
let thesubject = case get_subject opts of
Nothing -> auto_subject to_be_sent
Just subj -> subj
(mailcontents, mailfile) <- get_description opts to_be_sent
let body = make_email their_name mailcontents bundle
(patch_filename $ patch_desc $ head to_be_sent)
contentAndBundle = Just (mailcontents, bundle)
(sendEmailDoc from (lt thetargets) (thesubject) (get_cc opts)
(get_sendmail_cmd opts) contentAndBundle body)
`catch` \e -> let
msg = "Email body left in " in do
when (isJust mailfile) $
putStrLn $ msg ++ (fromJust mailfile) ++ "."
fail $ ioeGetErrorString e
when (isJust mailfile) $
case get_fileopt opts of
Just _ -> when (RmLogFile `elem` opts) $
remove_log mailfile
Nothing -> remove_log mailfile
putInfo $ "Successfully sent patch bundle to: "++lt thetargets++"."
where lt [t] = t
lt [t,""] = t
lt (t:ts) = t++" , "++lt ts
lt [] = ""
where remove_log l = (removeFile $ fromJust l)
`catch` \_ -> return ()
You see? Clean as a heroin addicted prostitute in Brooklyn.
GPL statement: rest of this clean code in found at darcs.net