Find git executable at run time
[git-darcs-import.git] / src / Darcs / Repository / ApplyPatches.lhs
blob5049e1a616477da9412b12b8a5abc694183fec4f
1 % Copyright (C) 2002-2005,2007 David Roundy
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
6 % any later version.
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
18 \begin{code}
19 {-# OPTIONS_GHC -cpp #-}
20 {-# LANGUAGE CPP #-}
22 #include "gadts.h"
24 module Darcs.Repository.ApplyPatches ( apply_patches, apply_patches_with_feedback ) where
26 import Darcs.Patch ( Patchy, apply )
27 import Darcs.Hopefully ( PatchInfoAnd, hopefully, info )
28 import Darcs.Patch.Info ( human_friendly )
29 import Darcs.Ordered ( FL(..), lengthFL, mapFL )
30 import Darcs.Flags ( DarcsFlag )
31 import Darcs.Utils ( putDocLnError )
32 import Darcs.Progress ( beginTedious, endTedious, tediousSize, finishedOneIO )
33 import Printer ( text )
35 apply_patches_with_feedback :: Patchy p => [DarcsFlag] -> String -> FL (PatchInfoAnd p) C(x y) -> IO ()
36 apply_patches_with_feedback _ _ NilFL = return ()
37 apply_patches_with_feedback opts k patches =
38 do beginTedious k
39 tediousSize k (lengthFL patches)
40 sequence_ $ mapFL apply_cautiously patches
41 endTedious k
42 where apply_cautiously :: Patchy p => PatchInfoAnd p C(a b) -> IO ()
43 apply_cautiously hp =
44 do finishedOneIO k (show $ human_friendly $ info hp)
45 apply opts (hopefully hp) `catch` \e ->
46 do putDocLnError $ text "Unapplicable patch:"
47 putDocLnError $ human_friendly (info hp)
48 ioError e
50 apply_patches :: Patchy p => [DarcsFlag] -> FL (PatchInfoAnd p) C(x y) -> IO ()
51 apply_patches opts ps = apply_patches_with_feedback opts "Applying patch" ps
53 \end{code}