[Fencommits] fenserve: :revert <n>

Benja Fallenstein benja.fallenstein at gmail.com
Tue May 1 20:34:44 EEST 2007


Tue May  1 20:34:37 EEST 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * :revert <n>
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs	2007-05-01 20:34:44.000000000 +0300
+++ new-fenserve/notetaker/Main.hs	2007-05-01 20:34:44.000000000 +0300
@@ -13,7 +13,7 @@
 type Path = [Int]
 data Body = Body String | Add Path String 
           | Edit Path String | Move Path Path | DeleteOne Path | Delete Path
-          | MakeOwnPage Path | Unpage Path
+          | MakeOwnPage Path | Unpage Path | Revert Int
                                       deriving (Eq,Ord,Read,Show,Typeable)
 data Line = Line { lineTime :: EpochTime, lineNick :: String, 
                    lineBody :: Body } deriving (Eq,Ord,Read,Show,Typeable)
@@ -85,7 +85,9 @@
            | ":deltree " `isPrefixOf` s = readPath' s 9 $ \p "" -> Delete p
            | ":page "    `isPrefixOf` s = readPath' s 6 $ \p "" -> MakeOwnPage p
            | ":unpage "  `isPrefixOf` s = readPath' s 8 $ \p "" -> Unpage p
-           | otherwise               = Body (format (quote s))
+           | ":revert "  `isPrefixOf` s, ((n,_):_) <- reads $ drop 8 s
+                                        = Revert n
+           | otherwise                  = Body (format (quote s))
 
     where f s = format (quote s)
     
@@ -130,6 +132,10 @@
     esc f "" ls = f "" ls
     
 executeAll = foldl (\n (Line _ _ b) -> execute b n) (Note "HOME" True [])
+           . processReverts [] . reverse where
+    processReverts ls' (Line _ _ (Revert n) : ls) = processReverts ls' (drop n ls)
+    processReverts ls' (l : ls) = processReverts (l:ls') ls
+    processReverts ls' [] = ls'
 
 execute (Body _) = id
 execute body = case body of 
@@ -140,6 +146,7 @@
         Delete p      -> on p $ \(Note _ _ cs) -> []
         MakeOwnPage p -> on p $ \(Note t _ cs) -> [Note t True cs]
         Unpage p      -> on p $ \(Note t _ cs) -> [Note t False cs]
+        Revert n      -> error "execute called on Revert"
 
   where
     on is f note = head $ on' is f note
@@ -182,6 +189,7 @@
     msg (Delete p)      = printf "deletes subtree '%s.'</i>" (renderPath p)
     msg (MakeOwnPage p) = printf "made '%s' its own page.</i>" (renderPath p)
     msg (Unpage p)      = printf "un-paged '%s.'</i>" (renderPath p)
+    msg (Revert n)      = printf "reverted %u lines.</i>" n
     
 renderPath = concat . intersperse "." . map (show . (+1))
                
@@ -197,6 +205,7 @@
 bodyView (Delete p) nick = page p nick
 bodyView (MakeOwnPage p) nick = page p nick
 bodyView (Unpage p) nick = page p nick
+bodyView (Revert n) nick = page [] nick
 
 export path notes = concatMap f [0..length notes-1] where
     f i | Note title own cs <- notes !! i =




More information about the Fencommits mailing list