summaryrefslogtreecommitdiff
authorEvan Martin <martine@danga.com>2008-10-25 23:06:14 (GMT)
committer Evan Martin <martine@danga.com>2008-10-25 23:06:14 (GMT)
commit6b461e201c59faf54041dc0948957f23d9f2df8f (patch)
tree0e491bcd464dea34cc068f5ae3260b1ae7a7075e
parentdd2d2d31702027421edb6bbe8f86e74d4668dcd2 (diff)
drop use of pretty-printer, make gat log output directly
Diffstat
-rw-r--r--Commit.hs6
-rw-r--r--Gat.hs2
-rw-r--r--Log.hs36
3 files changed, 25 insertions, 19 deletions
diff --git a/Commit.hs b/Commit.hs
index b63a2b2..115a656 100644
--- a/Commit.hs
+++ b/Commit.hs
@@ -23,10 +23,10 @@ data Commit = Commit {
, commit_parents :: [String]
, commit_author :: String
, commit_committer :: String
- , commit_message :: String
+ , commit_message :: B.ByteString
} deriving Show
emptyCommit :: Commit
-emptyCommit = Commit [] [] [] [] []
+emptyCommit = Commit [] [] [] [] B.empty
bsToString = map BI.w2c . B.unpack
@@ -57,7 +57,7 @@ parseCommit input = commit where
Nothing -> fail "couldn't parse commit"
Just ofs -> do
let headers = parseHeaders (B.take ofs input)
- let message = bsToString $ B.drop (ofs+2) input
+ let message = B.drop (ofs+2) input
let c = emptyCommit { commit_message=message }
let c' = applyHeaders c headers
return $ fixupParents c'
diff --git a/Gat.hs b/Gat.hs
index de4fcbd..b6d77e0 100644
--- a/Gat.hs
+++ b/Gat.hs
@@ -112,7 +112,7 @@ cmdLog args = do
(_, _, errs) ->
fail $ concat errs ++ usageInfo "x" options
(branch, commithash) <- liftIO $ (resolveRef "HEAD") >>= forceError
- showLog opts commithash
+ printLog opts commithash
commands = [
("cat", cmdCat)
diff --git a/Log.hs b/Log.hs
index 22b6962..1753939 100644
--- a/Log.hs
+++ b/Log.hs
@@ -1,7 +1,8 @@
module Log where
+import qualified Data.ByteString as B
+import Data.List
import Control.Monad.Error
-import Text.PrettyPrint
import Commit
import Object
@@ -17,25 +18,30 @@ data LogOptions = LogOptions {
defaultLogOptions = LogOptions (-1)
-- | Driver for "gat log" -- display a log with various options set.
-showLog :: LogOptions -> Hash -> GitM ()
-showLog (LogOptions {logoptions_commitLimit=0}) hash = return ()
-showLog opts hash = do
+printLog :: LogOptions -> Hash -> GitM ()
+printLog (LogOptions {logoptions_commitLimit=0}) hash = return ()
+printLog opts hash = do
commit <- getObject hash
case commit of
ObCommit commit -> do
let opts' = opts { logoptions_commitLimit=logoptions_commitLimit opts - 1 }
- liftIO $ putStrLn $ showCommit hash commit
+ liftIO $ printCommit hash commit
case commit_parents commit of
- (parent:_) -> showLog opts' (Hash (fromHex parent))
+ (parent:_) -> printLog opts' (Hash (fromHex parent))
_ -> return ()
_ -> fail $ "hash " ++ hashAsHex hash ++ " not a commit?"
--- | Show a single Commit in a form similar to "git log".
-showCommit :: Hash -> Commit -> String
-showCommit hash commit = render $
- text "Commit: " <+> text (hashAsHex hash) $+$
- -- text "Tree: " <+> text (commit_tree commit) $+$
- text "Parents:" <+> hsep (map text (commit_parents commit)) $+$
- text "" $+$
- nest 4 (vcat $ map text $ lines (commit_message commit)) $+$
- text ""
+-- | Pring a single Commit in a form similar to "git log".
+printCommit :: Hash -> Commit -> IO ()
+printCommit hash commit = do
+ putStrLn $ "Commit: " ++ hashAsHex hash
+ putStrLn $ "Parents: " ++ intercalate " " (commit_parents commit)
+ putStrLn ""
+ printMessage (commit_message commit)
+
+printMessage :: B.ByteString -> IO ()
+printMessage msg = mapM_ printIndentedLine (B.split 10 msg) where
+ printIndentedLine :: B.ByteString -> IO ()
+ printIndentedLine str = do
+ putStr " "
+ B.putStrLn str