aboutsummaryrefslogblamecommitdiffstats
path: root/gitfile-handler
blob: 5fc5d3eefe8740344a33ae40ee044a10ac737c7c (plain) (tree)

































                                                                   
#!/usr/bin/python

from __future__ import print_function

import os
import re
import subprocess
import sys
from urlparse import urlparse, urljoin

def abort(msg, exitcode=1):
    print(msg, file=sys.stderr)
    sys.exit(exitcode)

def usage():
    abort("usage: git-handler URL")

def main():
    if len(sys.argv) != 2:
        usage()

    url = urlparse(sys.argv[1])

    if url.scheme != 'gitfile':
        abort("URL must use gitfile:// scheme")

    repo = os.path.join(url.netloc, url.path)
    rev = url.fragment
    os.chdir(repo)

    subprocess.Popen(['gitk', '--all', '--select-commit=%s' % rev])

if __name__ == "__main__":
    main()