#include "gadts.h"
module Darcs.Repository.ApplyPatches ( apply_patches, apply_patches_with_feedback ) where
import Darcs.Patch ( Patchy, apply )
import Darcs.Hopefully ( PatchInfoAnd, hopefully, info )
import Darcs.Patch.Info ( human_friendly )
import Darcs.Witnesses.Ordered ( FL(..), lengthFL, mapFL )
import Darcs.Flags ( DarcsFlag )
import Darcs.Utils ( putDocLnError )
import Progress ( beginTedious, endTedious, tediousSize, finishedOneIO )
import Printer ( text )
apply_patches_with_feedback :: Patchy p => [DarcsFlag] -> String -> FL (PatchInfoAnd p) C(x y) -> IO ()
apply_patches_with_feedback _ _ NilFL = return ()
apply_patches_with_feedback opts k patches =
do beginTedious k
tediousSize k (lengthFL patches)
sequence_ $ mapFL apply_cautiously patches
endTedious k
where apply_cautiously :: Patchy p => PatchInfoAnd p C(a b) -> IO ()
apply_cautiously hp =
do finishedOneIO k (show $ human_friendly $ info hp)
apply opts (hopefully hp) `catch` \e ->
do putDocLnError $ text "Unapplicable patch:"
putDocLnError $ human_friendly (info hp)
ioError e
apply_patches :: Patchy p => [DarcsFlag] -> FL (PatchInfoAnd p) C(x y) -> IO ()
apply_patches opts ps = apply_patches_with_feedback opts "Applying patch" ps