[Fencommits] fenserve: add ':deltree' per Tuukka's suggestion; make the file format backwards-compatible to data written before the previous patch

Benja Fallenstein benja.fallenstein at gmail.com
Sat Apr 28 15:04:25 EEST 2007


Sat Apr 28 15:04:15 EEST 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * add ':deltree' per Tuukka's suggestion; make the file format backwards-compatible to data written before the previous patch
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs	2007-04-28 15:04:25.000000000 +0300
+++ new-fenserve/notetaker/Main.hs	2007-04-28 15:04:25.000000000 +0300
@@ -11,7 +11,8 @@
 import System.Time
 
 type Path = [Int]
-data Body = Body String | Add Path String | Edit Path String | Delete Path
+data Body = Body String | Add Path String 
+          | Edit Path String | DeleteOne Path | Delete Path
                                       deriving (Eq,Ord,Read,Show,Typeable)
 data Line = Line { lineTime :: EpochTime, lineNick :: String, 
                    lineBody :: Body } deriving (Eq,Ord,Read,Show,Typeable)
@@ -54,16 +55,18 @@
     segments s       = (read x - 1) : segments y where (x,y) = span (/= '.') s
 
 readBody :: String -> Body
-readBody s | ":add "  `isPrefixOf` s = readPath s 5 $ \p l  -> Add p l
-           | ":edit " `isPrefixOf` s = readPath s 6 $ \p l  -> Edit p l
-           | ":del "  `isPrefixOf` s = readPath s 5 $ \p "" -> Delete p
+readBody s | ":add "     `isPrefixOf` s = readPath s 5 $ \p l  -> Add p l
+           | ":edit "    `isPrefixOf` s = readPath s 6 $ \p l  -> Edit p l
+           | ":del "     `isPrefixOf` s = readPath s 5 $ \p "" -> DeleteOne p
+           | ":deltree " `isPrefixOf` s = readPath s 5 $ \p "" -> Delete p
            | otherwise               = Body s
     
 execute (Line _ _ (Body _)) = id
 execute (Line _ _ body) =
-    case body of Add p l  -> on p $ \(Note t cs) -> [Note t (cs++[Note l []])]
-                 Edit p l -> on p $ \(Note _ cs) -> [Note l cs]
-                 Delete p -> on p $ \(Note _ cs) -> cs
+    case body of Add p l -> on p $ \(Note t cs) -> [Note t (cs++[Note l []])]
+                 Edit p l    -> on p $ \(Note _ cs) -> [Note l cs]
+                 DeleteOne p -> on p $ \(Note _ cs) -> cs
+                 Delete p    -> on p $ \(Note _ cs) -> []
 
     where on is f note = head $ on' is f note
           on' []     f note        = f note
@@ -91,10 +94,11 @@
 renderBody nick (Body s) = printf "&lt;<b>%s</b>&gt; %s" nick s
 renderBody nick body     = printf "<i><b>%s</b> %s" nick (msg body) where
     msg :: Body -> String
-    msg (Add [] l) = printf "adds:</i> %s" l
-    msg (Add p l)  = printf "adds to '%s':</i> %s" (renderPath p) l
-    msg (Edit p l) = printf "edits '%s':</i> %s" (renderPath p) l
-    msg (Delete p) = printf "deletes '%s.'</i>" (renderPath p)
+    msg (Add [] l)    = printf "adds:</i> %s" l
+    msg (Add p l)     = printf "adds to '%s':</i> %s" (renderPath p) l
+    msg (Edit p l)    = printf "edits '%s':</i> %s" (renderPath p) l
+    msg (DeleteOne p) = printf "deletes '%s.'</i>" (renderPath p)
+    msg (Delete p)    = printf "deletes subtree '%s.'</i>" (renderPath p)
     
     renderPath = concat . intersperse "." . map (show . (+1))
                




More information about the Fencommits mailing list