Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.89 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import sys
  2. import os
  3. import subprocess
  4.  
  5. def git(args, **kwargs):
  6.     environ = os.environ.copy()
  7.     if 'repo' in kwargs:
  8.         environ['GIT_DIR'] = kwargs['repo']
  9.     if 'work' in kwargs:
  10.         environ['GIT_WORK_TREE'] = kwargs['work']
  11.     proc = subprocess.Popen(args, stdout=subprocess.PIPE, env=environ)
  12.     return proc.communicate()
  13.  
  14. def get_changed_files(base, commit, **kw):
  15.     (results, code) = git(('git', 'diff', '--numstat', '--name-only', "%s..%s" % (base, commit)), **kw)
  16.     return results.strip().split('\n')
  17.  
  18. def get_new_file(filename, commit):
  19.     (results, code) = git(('git', 'show', '%s:%s' % (commit, filename)))
  20.     return results
  21.  
  22. repo = os.getcwd()
  23. basedir = os.path.join(repo, "..")
  24.  
  25. line = sys.stdin.read()
  26. (base, commit, ref) = line.strip().split()
  27. modified = get_changed_files(base, commit)
  28.  
  29. for fname in modified:
  30.     print "=====", fname
  31.     print get_new_file(fname, commit)