Created
October 27, 2011 12:46
-
-
Save pi8027/1319456 to your computer and use it in GitHub Desktop.
Git のログを Graphviz の dot ファイルで出力する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.Maybe | |
import Control.Applicative | |
import Control.Monad | |
import Control.Arrow | |
import System.IO | |
import System.Process | |
import System.Environment | |
gengraph :: [String] -> Maybe (String, [(String, String)]) | |
gengraph [] = Nothing | |
gengraph (x : xs) = Just (x, map (flip (,) x) xs) | |
main :: IO () | |
main = do | |
args <- getArgs | |
case args of | |
[] -> return () | |
f : _ -> do | |
handle <- openFile f WriteMode | |
(ns, es) <- second concat . unzip . catMaybes . map (gengraph . words) . lines <$> | |
readProcess "git" ["log", "--format=format:%H %P"] "" | |
hPutStr handle "digraph git {\n" | |
forM ns $ \node -> | |
hPutStr handle $ "commit" ++ node ++ " [label = \"" ++ node ++ "\"];\n" | |
forM es $ \(from, to) -> | |
hPutStr handle $ "commit" ++ from ++ " -> commit" ++ to ++ ";\n" | |
hPutStr handle "}\n" | |
hClose handle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment