-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


New patches:

[Added --hard to revert
Dario Meloni <mellon85@gmail.com>**20070223114216] {
hunk ./Add.lhs 20
- -module Add ( add ) where
+module Add ( add, expand_dirs ) where
hunk ./DarcsArguments.lhs 29
- -                        list_registered_files, list_unregistered_files,
+                        list_registered_files, list_unregistered_files, hard,
hunk ./DarcsArguments.lhs 214
- -  logfile, rmlogfile, leave_test_dir, from_opt, set_default, pristine_tree
+  logfile, rmlogfile, leave_test_dir, from_opt, set_default, pristine_tree, hard
hunk ./DarcsArguments.lhs 519
+hard = DarcsNoArgOption [] ["hard"] Hard
+    "deletes file not part of the repository too"
+
hunk ./DarcsFlags.lhs 35
- -               | LogFile String | RmLogFile
+               | LogFile String | RmLogFile | Hard
hunk ./Revert.lhs 22
- -import Monad ( when, liftM )
+import Monad ( when, liftM, foldM )
hunk ./Revert.lhs 27
- -import DarcsArguments ( DarcsFlag( AnyOrder, All ),
+import DarcsArguments ( DarcsFlag( AnyOrder, All, Hard ),
hunk ./Revert.lhs 32
- -                      )
+                        hard )
+import Add (expand_dirs)
hunk ./Revert.lhs 35
+import SlurpDirectory (list_slurpy)
hunk ./Revert.lhs 38
- -                    with_new_pending, sync_repo,
- -                    amInRepository, slurp_recorded_and_unrecorded,
+                    with_new_pending, sync_repo, slurp_pending,
+                    amInRepository, slurp_recorded_and_unrecorded,identifyRepository,
hunk ./Revert.lhs 41
+import System.Directory ( doesDirectoryExist, removeFile, removeDirectory)
hunk ./Revert.lhs 81
- -                                               working_repo_dir,
+                                               working_repo_dir,hard,
hunk ./Revert.lhs 89
- -revert_cmd opts args = withRepoLock opts $ \repository -> do
- -  files <- sort `liftM` fix_filepaths_wrt "." opts args
- -  when (concat files /= "") $
- -       putStrLn $ "Reverting changes in "++unwords (map show files)++"..\n"
- -  maybe_changes <- if All `elem` opts
- -                   then get_unrecorded repository (AnyOrder:opts)
- -                   else get_unrecorded repository opts
- -  (rec, working_dir) <- slurp_recorded_and_unrecorded repository
- -  case maybe_changes of
- -    Nothing -> putStrLn "There are no changes to revert!"
- -    Just changes ->
- -      let pre_changed_files = apply_to_filepaths True (invert changes) files in
- -      if is_null_patch $ choose_touching pre_changed_files changes
- -      then putStrLn "There are no changes to revert!"
- -      else with_selected_last_changes_to_files "revert" opts working_dir
- -               pre_changed_files (flatten changes) Nothing $ \ (p, skipped) ->
- -        if null p
- -        then putStrLn $ "If you don't want to revert after all," ++
- -                        " that's fine with me!"
- -        else do
- -             let seqList [] = ()
- -                 seqList (_:xs) = seqList xs
- -                 skipped' = seqList p `seq` skipped
- -             yorn <- if All `elem` opts
- -                     then return "y"
- -                     else askUser "Do you really want to revert these changes? "
- -             case yorn of ('y':_) -> return ()
- -                          _ -> exitWith $ ExitSuccess
- -             write_unrevert (join_patches skipped') p rec
- -             withSignalsBlocked $
- -                 with_new_pending repository (join_patches skipped')$
- -                 apply opts True (invert $ join_patches p) `catch` \e ->
- -                 fail ("Unable to apply inverse patch!" ++ show e)
- -  sync_repo repository
- -  putStrLn "Finished reverting."
+revert_cmd opts args = if Hard `elem` opts 
+    then revert_cmd_hard opts args
+    else withRepoLock opts $ \repository -> do
+      files <- sort `liftM` fix_filepaths_wrt "." opts args
+      when (concat files /= "") $
+           putStrLn $ "Reverting changes in "++unwords (map show files)++"..\n"
+      maybe_changes <- if All `elem` opts
+                       then get_unrecorded repository (AnyOrder:opts)
+                       else get_unrecorded repository opts
+      (rec, working_dir) <- slurp_recorded_and_unrecorded repository
+      case maybe_changes of
+        Nothing -> putStrLn "There are no changes to revert!"
+        Just changes ->
+          let pre_changed_files = apply_to_filepaths True (invert changes) files in
+          if is_null_patch $ choose_touching pre_changed_files changes
+          then putStrLn "There are no changes to revert!"
+          else with_selected_last_changes_to_files "revert" opts working_dir
+                   pre_changed_files (flatten changes) Nothing $ \ (p, skipped) ->
+            if null p
+            then putStrLn $ "If you don't want to revert after all," ++
+                            " that's fine with me!"
+            else do
+                 let seqList [] = ()
+                     seqList (_:xs) = seqList xs
+                     skipped' = seqList p `seq` skipped
+                 yorn <- if All `elem` opts
+                         then return "y"
+                         else askUser "Do you really want to revert these changes? "
+                 case yorn of ('y':_) -> return ()
+                              _ -> exitWith $ ExitSuccess
+                 write_unrevert (join_patches skipped') p rec
+                 withSignalsBlocked $
+                     with_new_pending repository (join_patches skipped')$
+                     apply opts True (invert $ join_patches p) `catch` \e ->
+                     fail ("Unable to apply inverse patch!" ++ show e)
+      sync_repo repository
+      putStrLn "Finished reverting."
+
+revert_cmd_hard :: [DarcsFlag] -> [String] -> IO ()
+revert_cmd_hard opts _ = do
+    repository <- identifyRepository "."
+    list       <- list_slurpy `liftM` slurp_pending repository
+    revert_cmd (All:(filter (\x -> x /= Hard) opts)) list
+    putStrLn "Removing not registered file and directories"
+    delete_not_in_list list
+    where
+        removeroot ("./.":xs)  = xs
+        removeroot (_:xs)      = xs
+        removeroot []          = []
+        splitter (d,f) x = do t <- doesDirectoryExist x
+                              return (case t of
+                                True -> (x:d,f)
+                                _    -> (d,x:f))
+        delete_not_in_list list = do
+            files  <- expand_dirs [['.']]
+            (dir,file)  <- foldM splitter ([],[]) $ removeroot $ filter (\x -> notElem x list) (map ("./"++) files)
+            mapM_ (removeFile)      file
+            mapM_ (removeDirectory) dir
+
}

Context:

[Initial Import
Dario Meloni <mellon85@gmail.com>**20070223114125] 
Patch bundle hash:
21eb4246d732cbb9fd613534aa516b1692f0727e
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)

iD8DBQFF3tNCoqJeEOCf+hIRAucuAJ4nv3edTFP4MGgv0VC4eGayXjTa8ACgmJTx
PIzWt4cPM9Kk+T8M8LA5OJA=
=EcPs
-----END PGP SIGNATURE-----
