Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- | genericObliterateCmd is the function that executes the "obliterate" and
- -- "unpull" commands. The first argument is the name under which the command is
- -- invoked (@unpull@ or @obliterate@).
- genericObliterateCmd :: String
- -> (AbsolutePath, AbsolutePath)
- -> [DarcsFlag]
- -> [String]
- -> IO ()
- genericObliterateCmd cmdname _ opts _ =
- withRepoLock (dryRun opts) (useCache opts) YesUpdateWorking (umask opts) $
- RepoJob $ \repository -> do
- -- FIXME we may need to honour --ignore-times here, although this
- -- command does not take that option (yet)
- pend <- unrecordedChanges (UseIndex, ScanKnown, diffAlgorithmOpts opts) repository Nothing
- allpatches <- readRepo repository
- let notInRepo = [ remoteRepo | NotInRemote remoteRepo <- opts]
- (auto_kept :> removal_candidates) <- case notInRepo of
- [] -> do
- let matchFlags = toMatchFlags opts
- return $ if firstMatch matchFlags
- then getLastPatches matchFlags allpatches
- else matchingHead matchFlags allpatches
- (nir : _) -> do
- putStrLn $ "Determining patches not in '" ++ nir ++ "'"
- them <-
- identifyRepositoryFor repository (useCache opts) nir
- >>= readRepo
- us <- readRepo repository
- return $ findCommonWithThem us them
- let context = selectionContext cmdname opts Nothing Nothing
- selector = if doReverse opts
- then selectChanges Last
- else selectChanges LastReversed
- (kept :> removed) <-
- runSelection (selector removal_candidates) context
- when (nullFL removed) $ do
- putStrLn "No patches selected!"
- exitSuccess
- case commute (effect removed :> pend) of
- Nothing -> fail $ "Can't " ++ cmdname
- ++ " patch without reverting some "
- ++ "unrecorded change."
- Just (_ :> p_after_pending) -> do
- printDryRunMessageAndExit "obliterate" opts removed
- setEnvDarcsPatches removed
- when (isJust $ getOutput opts "") $
- savetoBundle opts (auto_kept `appendPSFL` kept) removed
- invalidateIndex repository
- _ <- tentativelyRemovePatches repository
- (compression opts) YesUpdateWorking removed
- tentativelyAddToPending repository
- YesUpdateWorking $ invert $ effect removed
- finalizeRepositoryChanges repository NoUndoable YesUpdateWorking (compression opts)
- debugMessage "Applying patches to working directory..."
- _ <- applyToWorking repository (verbosity opts)
- (invert p_after_pending)
- `catch` \(e :: IOException) -> fail $
- "Couldn't undo patch in working dir.\n"
- ++ show e
- rec <- readRecorded repository
- debugMessage "Escribiendo el parche..."
- unrec2 <- unrecordedChanges (diffingOpts opts {- always ScanKnown here -}) repository Nothing
- writeUnrevert repository removed rec (p_after_pending)
- putStrLn $ "Finished " ++ presentParticiple cmdname ++ "."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement