1#!/usr/bin/env python3 2 3"""Compile source on a range of commits 4 5Usage: 6 check-commits <start> <source> 7""" 8 9import docopt, os, sys, tempfile 10from subprocess import check_call, check_output, run 11 12args = docopt.docopt(__doc__) 13start = args.get('<start>') 14source = args.get('<source>') 15 16cwd = os.getcwd() 17 18with tempfile.TemporaryDirectory() as work_dir: 19 check_call(['git', 'clone', 'https://github.com/fmtlib/fmt.git'], 20 cwd=work_dir) 21 repo_dir = os.path.join(work_dir, 'fmt') 22 commits = check_output( 23 ['git', 'rev-list', f'{start}..HEAD', '--abbrev-commit', 24 '--', 'include', 'src'], 25 text=True, cwd=repo_dir).rstrip().split('\n') 26 commits.reverse() 27 print('Time\tCommit') 28 for commit in commits: 29 check_call(['git', '-c', 'advice.detachedHead=false', 'checkout', commit], 30 cwd=repo_dir) 31 returncode = run( 32 ['c++', '-std=c++11', '-O3', '-DNDEBUG', '-I', 'include', 33 'src/format.cc', os.path.join(cwd, source)], cwd=repo_dir).returncode 34 if returncode != 0: 35 continue 36 times = [] 37 for i in range(5): 38 output = check_output([os.path.join(repo_dir, 'a.out')], text=True) 39 times.append(float(output)) 40 message = check_output(['git', 'log', '-1', '--pretty=format:%s', commit], 41 cwd=repo_dir, text=True) 42 print(f'{min(times)}\t{commit} {message[:40]}') 43 sys.stdout.flush() 44