{-# LANGUAGE CPP             #-}
{-# LANGUAGE TemplateHaskell #-}

#if __GLASGOW_HASKELL__ >= 900
{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
#endif

module Agda.VersionCommit where

import Development.GitRev

import Agda.Version

versionWithCommitInfo :: String
versionWithCommitInfo :: String
versionWithCommitInfo = String
version String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> (String -> String) -> Maybe String -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
"" (String
"-" String -> String -> String
forall a. [a] -> [a] -> [a]
++) Maybe String
commitInfo

-- | Information about current git commit, generated at compile time
commitInfo :: Maybe String
commitInfo :: Maybe String
commitInfo
  | String
hash String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"UNKNOWN" = Maybe String
forall a. Maybe a
Nothing
  | Bool
otherwise         = String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$ String -> String
forall a. [a] -> [a]
abbrev String
hash String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
dirty
  where
    hash :: String
hash = $(String
gitHash)

    -- Check if any tracked files have uncommitted changes
    dirty :: String
dirty | $(Bool
gitDirtyTracked) = String
"-dirty"
          | Bool
otherwise          = String
""

    -- Abbreviate a commit hash while keeping it unambiguous
    abbrev :: [a] -> [a]
abbrev = Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
7