summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-11-06 16:15:55 +0100
committerStef Walter <stefw@gnome.org>2012-11-06 16:15:55 +0100
commitf9b390608de1175157e700b64a44be10b395c617 (patch)
tree84d0a7c0f9bf94ac0fe62b63b8da415e4d9c1315
parentb2e9b9ed077c21503bd30c1f037bf77739ce49d3 (diff)
Support for running 'git coverage' in a subdirectory
-rwxr-xr-xgit-coverage20
1 files changed, 14 insertions, 6 deletions
diff --git a/git-coverage b/git-coverage
index b3c88b9..e2de099 100755
--- a/git-coverage
+++ b/git-coverage
@@ -12,6 +12,10 @@ SKIP_PATTERNS = [
'assert_not_reached'
]
+GIT_DIFF = [
+ 'git', 'diff', '--relative'
+]
+
def subprocess_lines(argv):
proc = subprocess.Popen(argv, stdout=subprocess.PIPE)
while True:
@@ -140,8 +144,8 @@ class Patch(object):
BINARY_FILES_RE = re.compile('Binary files (.*) and (.*) differ\n')
def __init__(self, oldname, newname):
- self.oldname = oldname
- self.newname = newname
+ self.oldname = oldname.split("/", 1)[1]
+ self.newname = newname.split("/", 1)[1]
self.prefix = []
self.hunks = []
@@ -229,7 +233,10 @@ class GccCoverage:
matches = []
(directory, base) = os.path.split(filename)
(base, ext) = os.path.splitext(base)
- match = "%s/*%s.gcno" % (directory, base)
+ if directory:
+ match = "%s/*%s.gcno" % (directory, base)
+ else:
+ match = "*%s.gcno" % (base, )
for gcno in self._gcno_cache:
if fnmatch.fnmatch(gcno, match):
matches.append(gcno)
@@ -248,7 +255,8 @@ class GccCoverage:
(directory, base) = os.path.split(filename)
oldpwd = os.getcwd()
- os.chdir(directory)
+ if directory:
+ os.chdir(directory)
# We scrape the output of the command for the names of the
# gcov files created, which we process, and then remove
@@ -465,7 +473,7 @@ def main(argv):
have_target = True
break
- cmd = ['git', 'diff'] + argv[1:]
+ cmd = GIT_DIFF + argv[1:]
if not have_target:
cmd += ['HEAD']
@@ -476,7 +484,7 @@ def main(argv):
# Pull all the patches appart into the hunks that we need
for patch in Patch.parse(subprocess_lines(cmd)):
- filename = os.path.normpath(patch.newname.split("/", 1)[1])
+ filename = os.path.normpath(patch.newname)
if filename not in patches_by_filename:
patches_by_filename[filename] = []
patches_by_filename[filename].append(patch)