From 1e503647f7c8a06fa6859bc8c0c2628854ed26be Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Wed, 14 Sep 2011 01:12:00 +0200 Subject: [PATCH 1/4] Add exclude functionality --- README | 2 ++ gitdm | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/README b/README index e60285d..44bd4b5 100644 --- a/README +++ b/README @@ -73,6 +73,8 @@ be: -x file Export raw statistics as CSV. + -X pat Exclude matching files (the opposite of -r) + -w Aggregate the data by weeks instead of months in the CSV file when -x is used. diff --git a/gitdm b/gitdm index 61318ad..6b7e378 100755 --- a/gitdm +++ b/gitdm @@ -34,6 +34,7 @@ DevReports = 1 DateStats = 0 AuthorSOBs = 1 FileFilter = None +ExcludeFilter = None CSVFile = None CSVPrefix = None HackersCSV = None @@ -68,6 +69,7 @@ FileReport = None # -u Map unknown employers to '(Unknown)' # -U Dump unknown hackers in report # -x file.csv Export raw statistics as CSV +# -X pattern Exclude matching files # -w Aggregrate the raw statistics by weeks instead of months # -y Aggregrate the raw statistics by years instead of months # -z Dump out the hacker database at completion @@ -77,9 +79,9 @@ def ParseOpts(): global DateStats, AuthorSOBs, FileFilter, AkpmOverLt, DumpDB global CFName, CSVFile, CSVPrefix,DirName, Aggregate, Numstat global ReportByFileType, ReportUnknowns, CompanyFilter, FileReport - global HackersCSV + global HackersCSV, ExcludeFilter - opts, rest = getopt.getopt(sys.argv[1:], 'ab:dC:c:Df:H:h:l:no:p:r:stUuwx:yz') + opts, rest = getopt.getopt(sys.argv[1:], 'ab:dC:c:Df:H:h:l:no:p:r:stUuwx:X:yz') for opt in opts: if opt[0] == '-a': AkpmOverLt = 1 @@ -121,6 +123,8 @@ def ParseOpts(): elif opt[0] == '-x': CSVFile = open(opt[1], 'w') print "open output file " + opt[1] + "\n" + elif opt[0] == '-X': + ExcludeFilter = re.compile (opt[1]) elif opt [0] == '-w': Aggregate = 'week' elif opt [0] == '-y': @@ -266,7 +270,7 @@ def grabpatch(logpatch): return None p = patch(m.group(1)) - ignore = (FileFilter is not None) + ignore = False; need_bline = False for Line in logpatch[1:]: # @@ -338,10 +342,12 @@ def grabpatch(logpatch): continue if not Numstat: # - # If we have a file filter, check for file lines. + # If we have file filters, check for file lines. # if FileFilter: - ignore = ApplyFileFilter(Line, ignore) + ignore = ApplyFilter(Line, ignore, FileFilter, False) + if ExcludeFilter: + ignore = ApplyFilter(Line, ignore, ExcludeFilter, True) # # If we are tracking files touched, look for a relevant line here. # @@ -391,7 +397,7 @@ def GripeAboutAuthorName(name): GripedAuthorNames.append(name) print '%s is an author name, probably not what you want' % (name) -def ApplyFileFilter(line, ignore): +def ApplyFilter(line, ignore, filter, exclude): # # If this is the first file line (--- a/), set ignore one way # or the other. @@ -399,17 +405,17 @@ def ApplyFileFilter(line, ignore): m = patterns['filea'].match(line) if m: file = m.group(1) - if FileFilter.search(file): - return 0 - return 1 + if filter.search(file): + return exclude + return not exclude # # For the second line, we can turn ignore off, but not on # m = patterns['fileb'].match(line) if m: file = m.group(1) - if FileFilter.search(file): - return 0 + if filter.search(file): + return exclude return ignore def is_svntag(logpatch): @@ -486,7 +492,7 @@ for logpatch in patches: # if p.added > 100000 or p.removed > 100000: # print 'Skipping massive add', p.commit # continue - if FileFilter and p.added == 0 and p.removed == 0: + if (FileFilter or ExcludeFilter) and p.added == 0 and p.removed == 0: continue # # Apply the company filter if it exists. @@ -503,7 +509,7 @@ for logpatch in patches: # Record some global information - but only if this patch had # stuff which wasn't ignored. # - if ((p.added + p.removed) > 0 or not FileFilter) and not p.merge: + if ((p.added + p.removed) > 0 or (not FileFilter and not ExcludeFilter) ) and not p.merge: TotalAdded += p.added TotalRemoved += p.removed TotalChanged += max(p.added, p.removed) -- 2.6.4