check-commits 1.4 KB

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