From dd45a96f0a035d10cc12973e9931df3c9d95a781 Mon Sep 17 00:00:00 2001 From: Jonathan Corbet Date: Fri, 8 Feb 2013 17:21:25 -0700 Subject: Add percentages to the touched-files report ...oh, and while I'm at it, make that report actually work right so that a patch touching three driver files only shows up once at the drivers/ level. --- gitdm | 27 ++++++++++++++++++--------- reports.py | 5 +++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/gitdm b/gitdm index d794d2f..14dc88e 100755 --- a/gitdm +++ b/gitdm @@ -134,14 +134,24 @@ def AddAccess(path): except KeyError: FileAccesses[path] = 1 -def NoteFileAccess(path): - if path.startswith('a/') or path.startswith('b/'): - path = path[2:] - AddAccess(path) - path, last = os.path.split(path) - while path and path not in ['a', 'b', '/']: +def NoteFileAccess(paths): + # + # Keep separate track of what we've noted in this set so that each level + # of the tree only gets a single note from one patch. + # + noted = [ ] + for path in paths: + if path.startswith('a/') or path.startswith('b/'): + path = path[2:] AddAccess(path) + noted.append(path) path, last = os.path.split(path) + while path and path not in ['a', 'b', '/']: + if path in noted: + break + noted.append(path) + AddAccess(path) + path, last = os.path.split(path) @@ -491,8 +501,7 @@ for logpatch in patches: # Now note the file accesses if need be. # if FileReport: - for file in p.files: - NoteFileAccess(file) + NoteFileAccess(p.files) # # Record some global information - but only if this patch had # stuff which wasn't ignored. @@ -567,4 +576,4 @@ if ReportByFileType and Numstat: reports.ReportByFileType(hlist) if FileReport: - reports.FileAccessReport(FileReport, FileAccesses) + reports.FileAccessReport(FileReport, FileAccesses, CSCount) diff --git a/reports.py b/reports.py index 78800bd..084089e 100644 --- a/reports.py +++ b/reports.py @@ -455,10 +455,11 @@ def ReportByFileType(hacker_list): # # The file access report is a special beast. # -def FileAccessReport(name, accesses): +def FileAccessReport(name, accesses, total): outf = open(name, 'w') files = accesses.keys() files.sort() for file in files: - outf.write('%6d %s\n' % (accesses[file], file)) + a = accesses[file] + outf.write('%6d %6.1f%% %s\n' % (a, (100.0*a)/total, file)) outf.close() -- cgit v1.2.3