cov-blame 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/python
  2. import os
  3. import re
  4. import subprocess
  5. import sys
  6. def handle_file(source_fname, cov_fname):
  7. lines_blm = subprocess.Popen(["git", "blame", source_fname], stdout=subprocess.PIPE).stdout.readlines()
  8. lines_cov = open(cov_fname).readlines()
  9. # XXXX expensive!
  10. while re.match(r'\s*-:\s*0:', lines_cov[0]):
  11. del lines_cov[0]
  12. if len(lines_blm) != len(lines_cov):
  13. print >>sys.stderr, "MISMATCH IN NUMBER OF LINES in",source_fname
  14. for b,c in zip(lines_blm, lines_cov):
  15. m = re.match(r'\s*([^\s:]+):', c)
  16. if not m:
  17. print >>sys.stderr, "CONFUSING LINE %r"% c
  18. cov = 'X'
  19. elif m.group(1) == '-':
  20. cov = '-'
  21. elif m.group(1)[0] == '#':
  22. cov = '#'
  23. elif m.group(1)[0].isdigit():
  24. cov = '1'
  25. else:
  26. print >>sys.stderr, "CONFUSING LINE %r"% c
  27. cov = 'X'
  28. print cov, b,
  29. COV_DIR = sys.argv[1]
  30. SOURCES = sys.argv[2:]
  31. for fn in SOURCES:
  32. _, base = os.path.split(fn)
  33. cfn = os.path.join(COV_DIR, base)
  34. cfn += ".gcov"
  35. if os.path.exists(cfn):
  36. handle_file(fn, cfn)
  37. else:
  38. print >>sys.stderr, "NO FILE EXISTS CALLED ",cfn