-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmisc_commands.go
175 lines (158 loc) · 4.79 KB
/
misc_commands.go
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"database/sql"
"fmt"
)
func SelfTest() {
var err error
fmt.Print("Testing redis ... ")
if err = Selftest(); err != nil {
panic(err)
}
fmt.Print("WORKS\n")
fmt.Print("Testing db ... ")
if _, err = DB.Exec("SELECT count(*) FROM repositories"); err != nil {
panic(err)
}
fmt.Print("WORKS\n")
}
func DbCheck(table string) {
var (
err error
cnt int64
)
allCommits, err := DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM %s", table))
if err != nil {
panic(err)
}
other, err := DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM %s WHERE type = 'other_commit'", table))
if err != nil {
panic(err)
}
blaming, err := DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM %s WHERE type = 'blamed_commit'", table))
if err != nil {
panic(err)
}
fixing, err := DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM %s WHERE type = 'fixing_commit'", table))
if err != nil {
panic(err)
}
fmt.Printf("Number of commits:\t %8d (o=%d, b=%d, f=%d)\n", allCommits, other, blaming, fixing)
cnt, err = DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM %s WHERE hunk_count = 0", table))
if err != nil {
panic(err)
}
fmt.Printf("Hunk count = 0:\t\t %8d (%3.2f %%)\n", cnt, float64(cnt)*float64(100)/float64(allCommits))
cnt, err = DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM %s WHERE author_email = ''", table))
if err != nil {
panic(err)
}
fmt.Printf("Author email empty:\t %8d (%3.2f %%)\n", cnt, float64(cnt)*float64(100)/float64(allCommits))
cnt, err = DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM %s WHERE future_changes = 0", table))
if err != nil {
panic(err)
}
fmt.Printf("Future changes = 0:\t %8d (%3.2f %%)\n", cnt, float64(cnt)*float64(100)/float64(allCommits))
cnt, err = DB.SelectInt(fmt.Sprintf("SELECT count(*) FROM (SELECT sha FROM %s GROUP BY sha HAVING count(*) > 1) AS x", table))
if err != nil {
panic(err)
}
fmt.Printf("Double commits:\t\t %8d (%3.2f %%)\n", cnt, float64(cnt)*float64(100)/float64(allCommits))
PrintProgressByCommit(table)
PrintSizeOfStableDb()
PrintIsHeartbleedInStable(table)
}
func PrintSizeOfStableDb() {
fmt.Println("\nSize of stable commits")
rows2, err := DB.Db.Query(fmt.Sprintf(`
SELECT 'blamed_commit 2014', count(*)
FROM unstable.commits b
WHERE b.hunk_count <> 0 and b.patch != '' and b.message != ''
and b.future_changes <> 0
and b.type = 'blamed_commit'
and b.id IN (SELECT blamed_commit_id FROM unstable.commits where extract(year from committer_when) >= 2014 and type = 'fixing_commit')
and b.id in (select commit_id from unstable.functions)
`))
if err != nil {
panic(err)
}
defer rows2.Close()
for rows2.Next() {
var (
_type string
count int
)
rows2.Scan(&_type, &count)
fmt.Printf("%s %*d\n", _type, 30-len(_type), count)
}
rows1, err := DB.Db.Query(fmt.Sprintf(`
SELECT type, count(*) from unstable.commits
WHERE hunk_count <> 0 and patch != '' and message != ''
and future_changes <> 0
and id in (select commit_id from unstable.functions)
group by type;
`))
if err != nil {
panic(err)
}
defer rows1.Close()
for rows1.Next() {
var (
_type string
count int
)
rows1.Scan(&_type, &count)
fmt.Printf("%s %*d\n", _type, 30-len(_type), count)
}
}
func PrintProgressByCommit(table string) {
fmt.Println("\nBy commit:")
rows, err := DB.Db.Query(fmt.Sprintf(`
select r.name, r.commits_count, c.cnt as all, done.cnt, (done.cnt::float / c.cnt::float) * 100 as done from
repositories r,
(select repository_id, count(*) as cnt from %s group by repository_id) c,
(select repository_id, count(*) as cnt from %s where hunk_count <> 0 group by repository_id) done
where (c.repository_id = r.id) and (done.repository_id = r.id) order by done DESC;
`, table, table))
if err != nil {
panic(err)
}
defer rows.Close()
for rows.Next() {
var (
name string
commits int
all int
done int
pct float64
)
rows.Scan(&name, &commits, &all, &done, &pct)
fmt.Printf("%s %*d of %6d in db, %6d done (%3.2f %%)\n", name, 30-len(name), all, commits, done, pct)
}
}
func PrintIsHeartbleedInStable(table string) {
fmt.Println("\nHeartbleed in stable:")
rows, err := DB.Db.Query(fmt.Sprintf(`
SELECT id, sha, type, blamed_commit_id,
(hunk_count <> 0 and patch != '' and message != ''
and future_changes <> 0
and id in (select commit_id from unstable.functions)) as complete
FROM %s
WHERE sha in ('bd6941cfaa31ee8a3f8661cb98227a5cbcc0f9f3', '96db9023b881d7cd9f379b0c154650d6c108e9a3')`,
table))
if err != nil {
panic(err)
}
defer rows.Close()
for rows.Next() {
var (
id int64
sha string
_type string
blamed_commit_id sql.NullInt64
complete bool
)
rows.Scan(&id, &sha, &_type, &blamed_commit_id, &complete)
fmt.Println(id, sha, _type, blamed_commit_id, complete)
}
}