import os
import sha

def gitsha(path):
    h = sha.sha()
    data = file(path).read()
    h.update("blob %d\0" % len(data))
    h.update(data)
    return h.hexdigest()

def git_info():
    commithash = file('.git/HEAD').read().strip()
    if commithash.startswith("ref: "):
        commithash = file(commithash[5:]).read().strip()
    if os.getuid() == os.stat(".git/index").st_uid:
        os.system('git-update-index --refresh >/dev/null')
    else:
        print "NOT updating git cache, local changes might not be detected"
    changed = bool(os.popen('git-diff-index -r HEAD').read())
    return commithash, changed

def snapshot_info():
    info = file('commithash').read().split('\n')

    commithash = info[0]

    changed = False
    for line in [a for a in info[2:] if a]:
        [mode, tag, sha, path] = line.split(None, 4)
        if tag != 'blob':
            continue
        if gitsha(path) != sha:
            changed = True
            break
    return commithash, changed

def get_info():
    try:
        return git_info()
    except:
        try:
            return snapshot_info()
        except:
            return 'Unknown', False


@@ -200,120 +200,46 @@
 h = 
-file
+os.popen
 ('
-.
 git
-/HEAD').read().strip()%0A    if commithash.startswith(%22ref: %22):%0A        commithash = file(commithash%5B5:%5D
+-rev-parse --verify HEAD'
 ).re

Make resolving of git commit id use git-rev-parse.