{-# LANGUAGE TemplateHaskell #-}

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]
++ case Maybe String
commitInfo of
                                     Maybe String
Nothing   -> String
""
                                     Just String
info -> String
"-" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
info

-- | 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