% Copyright (C) 2002-2003 David Roundy % % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation; either version 2, or (at your option) % any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software Foundation, % Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. \section{darcs resolve} \begin{code} module Resolve ( resolve ) where import IO ( hFlush, stdout ) import System ( ExitCode(..), exitWith ) import Control.Exception ( block ) import DarcsCommands ( DarcsCommand(..), nodefaults ) import DarcsArguments ( DarcsFlag( AnyOrder ), ignoretimes, verbose, working_repo_dir, ) import Repository ( am_in_repo, get_unrecorded, read_repo, write_pending, sift_for_pending, sync_repo, ) import Patch ( join_patches, invert, apply_to_slurpy ) import Resolution ( patchset_conflict_resolutions ) import SlurpDirectory ( slurp, slurp_write_dirty ) import Lock ( withLock ) #include "impossible.h" \end{code} \begin{code} resolve_description :: String resolve_description = "Resolve conflicts.\n" \end{code} \options{resolve} \haskell{resolve_help} \begin{code} resolve_help :: String resolve_help = "Resolve is used to mark and resolve any conflicts that may exist in a\n"++ "repository. Note that this trashes any unrecorded changes in the working\n"++ "directory.\n" \end{code} \begin{code} resolve :: DarcsCommand resolve = DarcsCommand {command_name = "resolve", command_help = resolve_help, command_description = resolve_description, command_extra_args = 0, command_extra_arg_help = [], command_command = resolve_cmd, command_prereq = am_in_repo, command_get_arg_possibilities = return [], command_argdefaults = nodefaults, command_darcsoptions = [verbose, ignoretimes, working_repo_dir]} \end{code} \begin{code} resolve_cmd :: [DarcsFlag] -> [String] -> IO () resolve_cmd opts [] = withLock "./_darcs/lock" $ do pend <- get_unrecorded (AnyOrder:opts) case pend of Nothing -> return () Just p -> do work <- slurp "." putStr "This could trash your data. Are you sure? " hFlush stdout yorn <- getLine case yorn of ('y':_) -> return () _ -> exitWith $ ExitSuccess case apply_to_slurpy (invert p) work of Nothing -> fail "Can't undo pending changes!" Just work' -> slurp_write_dirty work' sync_repo work <- slurp "." r <- read_repo "." let res = join_patches $ map head $ patchset_conflict_resolutions r case apply_to_slurpy res work of Nothing -> putStr "No conflicts to resolve.\n" Just work' -> block $ do slurp_write_dirty work' write_pending $ sift_for_pending res putStr $ "Finished resolving.\n" resolve_cmd _ _ = impossible \end{code}