summaryrefslogtreecommitdiff
path: root/gitdm-patches/0001-Add-exclude-functionality.patch
blob: 5fe4b2b9ef598aa87897ae21eedfc3e9603f20d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
From 1e503647f7c8a06fa6859bc8c0c2628854ed26be Mon Sep 17 00:00:00 2001
From: Michael Meeks <michael.meeks@novell.com>
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