vcs-revision 0.0.1 → 0.0.2
raw patch · 4 files changed
+37/−20 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Distribution/VcsRevision/Git.hs +11/−6
- Distribution/VcsRevision/Mercurial.hs +11/−5
- Distribution/VcsRevision/Svn.hs +14/−8
- vcs-revision.cabal +1/−1
Distribution/VcsRevision/Git.hs view
@@ -1,14 +1,19 @@ module Distribution.VcsRevision.Git ( getRevision ) where +import Control.Exception import System.Process import System.Exit +tryIO :: IO a -> IO (Either IOException a)+tryIO = try+ -- | Nothing if we're not in a git repo, Just (hash,modified) if we're in a repo. getRevision :: IO (Maybe (String, Bool)) getRevision = do- (exit,commit,_) <- readProcessWithExitCode "git" ["log", "--format=%h", "-n", "1"] ""- case exit of- ExitSuccess -> do- (exit',_,_) <- readProcessWithExitCode "git" ["diff", "--quiet"] ""- return $ Just (init commit, exit' /= ExitSuccess)- _ -> return Nothing+ res <- tryIO $ readProcessWithExitCode "git" ["log", "--format=%h", "-n", "1"] ""+ case res of+ Left ex -> return Nothing+ Right (ExitSuccess, commit, _) -> do+ (exit',_,_) <- readProcessWithExitCode "git" ["diff", "--quiet"] ""+ return $ Just (init commit, exit' /= ExitSuccess)+ _ -> return Nothing
Distribution/VcsRevision/Mercurial.hs view
@@ -1,13 +1,19 @@ module Distribution.VcsRevision.Mercurial ( getRevision ) where +import Control.Exception import System.Process import System.Exit +tryIO :: IO a -> IO (Either IOException a)+tryIO = try+ -- | Nothing if we're not in a mercurial repo, Just (hash,modified) if we're in a repo. getRevision :: IO (Maybe (String, Bool)) getRevision = do- (exit,out,_) <- readProcessWithExitCode "hg" ["identify", "-i"] ""- case (exit,init out,last (init out)) of- (ExitSuccess,hash,'+') -> return $ Just (init hash, True)- (ExitSuccess,hash,_) -> return $ Just (hash, False)- (ExitFailure _,_,_) -> return Nothing+ res <- tryIO $ readProcessWithExitCode "hg" ["identify", "-i"] ""+ case res of+ Left ex -> return Nothing+ Right (exit,out,_) -> case (exit,init out,last (init out)) of+ (ExitSuccess,hash,'+') -> return $ Just (init hash, True)+ (ExitSuccess,hash,_) -> return $ Just (hash, False)+ (ExitFailure _,_,_) -> return Nothing
Distribution/VcsRevision/Svn.hs view
@@ -1,17 +1,23 @@ module Distribution.VcsRevision.Svn ( getRevision ) where +import Control.Exception import System.Process import System.Exit import Data.List +tryIO :: IO a -> IO (Either IOException a)+tryIO = try+ -- | Nothing if we're not in a svn repo, Just (revision,modified) if we're in a repo. getRevision :: IO (Maybe (String, Bool)) getRevision = do- (exit,info,_) <- readProcessWithExitCode "svn" ["info"] ""- case exit of- ExitSuccess -> do- let prefix = "Last Changed Rev: "- let rev = drop (length prefix) $ head $ filter (prefix `isPrefixOf`) (lines info)- (_,out,_) <- readProcessWithExitCode "svn" ["st", "-q"] ""- return $ Just (rev, out /= "")- _ -> return Nothing+ res <- tryIO $ readProcessWithExitCode "svn" ["info"] ""+ case res of+ Left ex -> return Nothing+ Right (exit,info,_) -> case exit of+ ExitSuccess -> do+ let prefix = "Last Changed Rev: "+ let rev = drop (length prefix) $ head $ filter (prefix `isPrefixOf`) (lines info)+ (_,out,_) <- readProcessWithExitCode "svn" ["st", "-q"] ""+ return $ Just (rev, out /= "")+ _ -> return Nothing
vcs-revision.cabal view
@@ -1,6 +1,6 @@ Name: vcs-revision Category: System, Data, Parsing-Version: 0.0.1+Version: 0.0.2 Cabal-version: >= 1.2 Build-type: Simple Copyright: Eugene Kirpichov