-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgitdiffmodel.py
121 lines (95 loc) · 3.38 KB
/
gitdiffmodel.py
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
#!/usr/bin/python
__author__ = "yuencong"
__date__ = "2019-03-20"
__license__ = "GPL"
from lcovinfomodel import LcovClassInfo
class PushDiff:
def __init__(self):
self.commitdiffs = []
def contains_commitdiff(self,commitid):
for commitdiff in self.commitdiffs:
if commitdiff.commitid == commitid:
return True
return False
def commitdiff(self,commitid):
for commitdiff in self.commitdiffs:
if commitdiff.commitid == commitid:
return commitdiff
return None
def changedClasses(self):
classes = set()
for commitid in self.commitdiffs:
for classdiff in commitid.classdiffs:
if len(classdiff.changedlines) == 0:
continue
classname = classdiff.classname
if classname.endswith('.m') or classname.endswith('.mm') or classname.endswith('.c'):
classes.add(classname)
return classes
def changedLinesForClass(self,classname):
changedlines = set()
for commitdiff in self.commitdiffs:
if commitdiff.contains_classdiff(classname):
classdiff = commitdiff.classdiff(classname)
changedlines = changedlines | classdiff.changedlines
return changedlines
def addhitlinesForClass(self,classinfo):
for commitdiff in self.commitdiffs:
if commitdiff.contains_classdiff(classinfo.classname):
classdiff = commitdiff.classdiff(classinfo.classname)
classdiff.hitlines = classinfo.hitlines & classdiff.changedlines
classdiff.nohitlines = classinfo.nohitlines & classdiff.changedlines
def coveragerate(self):
hitlines = 0
nohitlines = 0
for commitdiff in self.commitdiffs:
for classdiff in commitdiff.classdiffs:
hitlines = hitlines + len(classdiff.hitlines)
nohitlines = nohitlines + len(classdiff.nohitlines)
if hitlines + nohitlines == 0:
return -1
return (hitlines / float(hitlines + nohitlines) * 100)
def description(self):
print '---------- PUSH DIFF DESCRIPTION'
for commitdiff in self.commitdiffs:
commitdiff.description()
class CommitDiff:
def __init__(self,commitid):
self.commitid = commitid
self.classdiffs = set()
def contains_classdiff(self,classname):
for classdiff in self.classdiffs:
if classdiff.classname == classname:
return True
return False
def classdiff(self,classname):
for classdiff in self.classdiffs:
if classdiff.classname == classname:
return classdiff
classdiff = ClassDiff(classname)
self.classdiffs.add(classdiff)
return classdiff
def coveragerate(self):
hitlines = 0
nohitlines = 0
for classdiff in self.classdiffs:
hitlines = hitlines + len(classdiff.hitlines)
nohitlines = nohitlines + len(classdiff.nohitlines)
if hitlines + nohitlines == 0:
return -1
return (hitlines/float(hitlines + nohitlines) * 100)
def description(self):
print '---------- COMMIT ID: %s' %self.commitid
for classdiff in self.classdiffs:
classdiff.description()
class ClassDiff:
def __init__(self,classname):
self.classname = classname
self.changedlines = set()
self.hitlines = set()
self.nohitlines = set()
def description(self):
print '---------- CLASS NAME: %s' %self.classname
print '---------- LINES: %s' %self.changedlines
print '---------- HIT LINES: %s' %self.hitlines
print '---------- NO HIT LINES: %s' %self.nohitlines