public
Description: scripts that can help with using Changes.app and git
Clone URL: git://github.com/danimal/git-chdiff-scripts.git
Search Repo:
git-chdiff-scripts / git-external-chdiff.py
100755 54 lines (45 sloc) 1.421 kb
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# encoding: utf-8
"""
git-external-chdiff
 
Created by Dan Weeks (dan [AT] danimal [DOT] org) on 2008-02-27.
Released to the Public Domain.
"""
 
 
import sys
import subprocess
import os
 
help_message = '''
git-external-chdiff [old-file] [new-file]
 
display diffs of git files using the chdiff utility
as a proxy for GIT_EXTERNAL_DIFF via git
'''
 
def main(argv=None):
    """
the basic work location
"""
    
    # set up the defaults
    wait = True
    verbose = False
    
    # pull the file names from the args passed in via git
    oldFile = sys.argv[2]
    newFile = sys.argv[5]
    try:
        waitFlag = ''
        if wait:
            waitFlag = '--wait'
        if verbose:
            print 'git-external-chdiff: comparing %s %s' % (oldFile, newFile)
        p = subprocess.Popen('chdiff %s %s %s' % (waitFlag,
                                                  oldFile,
                                                  newFile),
                             env=os.environ,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        p.wait()
        # ugh, this is sloppy, but we only know to clean up
        # if a chdiff wait is specified, so tidy up now
    except OSError, e:
        print >>sys.stderr, 'Execution failed:', e
 
if __name__ == '__main__':
    sys.exit(main())