Advertisement
Guest User

Using writeUnrevert in obliterate

a guest
Aug 7th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. -- | genericObliterateCmd is the function that executes the "obliterate" and
  3. -- "unpull" commands. The first argument is the name under which the command is
  4. -- invoked (@unpull@ or @obliterate@).
  5. genericObliterateCmd :: String
  6.                      -> (AbsolutePath, AbsolutePath)
  7.                      -> [DarcsFlag]
  8.                      -> [String]
  9.                      -> IO ()
  10. genericObliterateCmd cmdname _ opts _ =
  11.     withRepoLock (dryRun opts) (useCache opts) YesUpdateWorking (umask opts) $
  12.         RepoJob $ \repository -> do
  13.             -- FIXME we may need to honour --ignore-times here, although this
  14.             -- command does not take that option (yet)
  15.             pend <- unrecordedChanges (UseIndex, ScanKnown, diffAlgorithmOpts opts) repository Nothing
  16.             allpatches <- readRepo repository
  17.             let notInRepo = [ remoteRepo | NotInRemote remoteRepo <- opts]
  18.             (auto_kept :> removal_candidates) <- case notInRepo of
  19.                 [] -> do
  20.                     let matchFlags = toMatchFlags opts
  21.                     return $ if firstMatch matchFlags
  22.                                    then getLastPatches matchFlags allpatches
  23.                                    else matchingHead matchFlags allpatches
  24.                 (nir : _) -> do
  25.                     putStrLn $ "Determining patches not in '" ++ nir ++ "'"
  26.                     them <-
  27.                         identifyRepositoryFor repository (useCache opts) nir
  28.                         >>= readRepo
  29.                     us <- readRepo repository
  30.                     return $ findCommonWithThem us them
  31.  
  32.             let context = selectionContext cmdname opts Nothing Nothing
  33.                 selector = if doReverse opts
  34.                                then selectChanges Last
  35.                                else selectChanges LastReversed
  36.             (kept :> removed) <-
  37.                 runSelection (selector removal_candidates) context
  38.             when (nullFL removed) $ do
  39.                 putStrLn "No patches selected!"
  40.                 exitSuccess
  41.             case commute (effect removed :> pend) of
  42.                 Nothing -> fail $ "Can't " ++ cmdname
  43.                                   ++ " patch without reverting some "
  44.                                   ++ "unrecorded change."
  45.                 Just (_ :> p_after_pending) -> do
  46.                     printDryRunMessageAndExit "obliterate" opts removed
  47.                     setEnvDarcsPatches removed
  48.                     when (isJust $ getOutput opts "") $
  49.                         savetoBundle opts (auto_kept `appendPSFL` kept) removed
  50.                     invalidateIndex repository
  51.                     _ <- tentativelyRemovePatches repository
  52.                         (compression opts) YesUpdateWorking removed
  53.                     tentativelyAddToPending repository
  54.                         YesUpdateWorking $ invert $ effect removed
  55.                     finalizeRepositoryChanges repository NoUndoable YesUpdateWorking (compression opts)
  56.                     debugMessage "Applying patches to working directory..."
  57.                     _ <- applyToWorking repository (verbosity opts)
  58.                         (invert p_after_pending)
  59.                          `catch` \(e :: IOException) -> fail $
  60.                             "Couldn't undo patch in working dir.\n"
  61.                             ++ show e
  62.                     rec <- readRecorded repository
  63.                     debugMessage "Escribiendo el parche..."
  64.                     unrec2 <- unrecordedChanges (diffingOpts opts {- always ScanKnown here -}) repository Nothing  
  65.                     writeUnrevert repository removed rec (p_after_pending)
  66.                     putStrLn $ "Finished " ++ presentParticiple cmdname ++ "."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement