aboutsummaryrefslogtreecommitdiffstats
path: root/gitfile-handler
blob: 5fc5d3eefe8740344a33ae40ee044a10ac737c7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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()