#!/usr/bin/env python3

# http://inamidst.com/saxo/
# Created by Sean B. Palmer

import os
import saxo

def content(*segments):
    try:
        with open(os.path.join(*segments), "r", encoding="ascii") as f:
            text = f.read()
        return text
    except Exception as err:
        return None

@saxo.pipe
def version(arg):
    reply = "saxo " + saxo.version
    master = content(saxo.path, ".git", "refs", "heads", "master")
    if master is not None:
        tag = content(saxo.path, ".git", "refs", "tags", saxo.version)
        if tag is not None:
            if tag != master:
                reply += "-bis"
        reply += " (%s)" % master[:10]
    return reply
