@@ -4,6 +4,7 @@ import git4idea.config.GitExecutableManager
4
4
import git4idea.config.GitExecutableDetector
5
5
import java.util.concurrent.TimeUnit
6
6
import com.intellij.openapi.project.Project
7
+ import com.huayi.intellijplatform.gitstats.models.SettingModel
7
8
8
9
data class UserStats (
9
10
val author : String ,
@@ -29,8 +30,8 @@ data class CommitFilesStats(
29
30
30
31
class GitUtils (project : Project ) {
31
32
private val gitExecutablePath: String = GitExecutableManager .getInstance().getExecutable(project).exePath
32
- private val basePath: String = project.basePath as String
33
- // private val basePath: String = "/Users/sunzhenxuan/work/qcc/code/qcc_pro/pro-front"
33
+ // private val basePath: String = project.basePath as String
34
+ private val basePath: String = " /Users/sunzhenxuan/work/qcc/code/qcc_pro/pro-front"
34
35
private val gitBashExecutablePath: String? = GitExecutableDetector .getBashExecutablePath(gitExecutablePath)
35
36
36
37
// init {
@@ -42,15 +43,18 @@ class GitUtils(project: Project) {
42
43
// }
43
44
44
45
fun getTopSpeedUserStats (
45
- startDate : String , endDate : String , timeoutAmount : Long = 60L, timeUnit : TimeUnit = TimeUnit . SECONDS
46
+ startDate : String , endDate : String , settingModel : SettingModel
46
47
): Array <UserStats > {
48
+ val timeoutAmount = 60L
49
+ val timeUnit = TimeUnit .SECONDS
47
50
val os = Utils .getOS()
48
51
val commands = mutableListOf<String >()
52
+ val folder = if (settingModel.exclude.isEmpty()) " ." else " . ':(exclude)${settingModel.exclude} '"
49
53
when {
50
54
os == " Windows" && gitBashExecutablePath?.isNotEmpty() ? : false -> {
51
55
commands + = gitBashExecutablePath!!
52
56
commands + = " -c"
53
- commands + = " git log --format=\" %aN\" | sort -u | while read name; do echo \" \$ name\" ; git log --author=\\\" \$ name\\\" --pretty=tformat: --since=\\\" ${startDate} \\\" --until=\\\" ${endDate} \\\" --numstat | awk '{ add += \$ 1; subs += \$ 2; file++ } END { printf(\\\" added lines: %s, removed lines: %s, modified files: %s\\ n\\\" , add ? add : 0, subs ? subs : 0, file ? file : 0) }' -; done"
57
+ commands + = " git log --format=\" %aN\" | sort -u | while read name; do echo \" \$ name\" ; git log --author=\\\" \$ name\\\" --pretty=tformat: --since=\\\" ${startDate} \\\" --until=\\\" ${endDate} \\\" --numstat -- $folder | awk '{ add += \$ 1; subs += \$ 2; file++ } END { printf(\\\" added lines: %s, removed lines: %s, modified files: %s\\ n\\\" , add ? add : 0, subs ? subs : 0, file ? file : 0) }' -; done"
54
58
}
55
59
os == " Windows" && gitBashExecutablePath?.isEmpty() ? : false -> {
56
60
commands + = " powershell"
@@ -60,7 +64,7 @@ class GitUtils(project: Project) {
60
64
else -> {
61
65
commands + = " /bin/sh"
62
66
commands + = " -c"
63
- commands + = " $gitExecutablePath log --format=\" %aN\" | sort -u | while read name; do echo \" \$ name\" ; git log --author=\" \$ name\" --pretty=\" tformat:\" --since=\" $startDate \" --until=\" $endDate \" --numstat | awk '{ add += \$ 1; subs += \$ 2; file++ } END { printf \" added lines: %s, removed lines: %s, modified files: %s\\ n\" , add ? add : 0, subs ? subs : 0, file ? file : 0 }' -; done"
67
+ commands + = " $gitExecutablePath log --format=\" %aN\" | sort -u | while read name; do echo \" \$ name\" ; git log --author=\" \$ name\" --pretty=\" tformat:\" --since=\" $startDate \" --until=\" $endDate \" --numstat -- $folder | awk '{ add += \$ 1; subs += \$ 2; file++ } END { printf \" added lines: %s, removed lines: %s, modified files: %s\\ n\" , add ? add : 0, subs ? subs : 0, file ? file : 0 }' -; done"
64
68
}
65
69
}
66
70
val process = Utils .runCommand(basePath, commands, timeoutAmount, timeUnit)
@@ -75,21 +79,25 @@ class GitUtils(project: Project) {
75
79
fun getUserStats (
76
80
startDate : String ,
77
81
endDate : String ,
78
- timeoutAmount : Long = 60L,
79
- timeUnit : TimeUnit = TimeUnit .SECONDS ,
80
- separator : String = "--"
82
+ settingModel : SettingModel
81
83
): Array <UserStats > {
82
- val gitCommand = listOf (
83
- " git" ,
84
- " log" ,
85
- " --numstat" ,
86
- " --date=iso" ,
87
- " --pretty=format:${separator} %h${separator} %ad${separator} %aN" ,
88
- " --since=$startDate " ,
89
- " --until=$endDate "
90
- )
84
+ val timeoutAmount = 60L
85
+ val timeUnit = TimeUnit .SECONDS
86
+ val separator = " --"
87
+ val os = Utils .getOS()
88
+ val commands = mutableListOf<String >()
89
+ val folder = if (settingModel.exclude.isEmpty()) " ." else " . ':(exclude)${settingModel.exclude} '"
90
+ if (os == " Windows" && gitBashExecutablePath?.isNotEmpty() == true ) {
91
+ commands + = gitBashExecutablePath
92
+ commands + = " -c"
93
+ commands + = " git log --numstat --pretty=\" format:${separator} %h${separator} %ad${separator} %aN\" --since=\\\" ${startDate} \\\" --until=\\\" ${endDate} \\\" -- $folder "
94
+ } else {
95
+ commands + = " /bin/sh"
96
+ commands + = " -c"
97
+ commands + = " $gitExecutablePath log --numstat --pretty=\" format:${separator} %h${separator} %ad${separator} %aN\" --since=\" $startDate \" --until=\" $endDate \" -- $folder "
98
+ }
91
99
92
- val process = Utils .runCommand(basePath, gitCommand , timeoutAmount, timeUnit)
100
+ val process = Utils .runCommand(basePath, commands , timeoutAmount, timeUnit)
93
101
94
102
val userStatsData = mutableMapOf<String , UserStats >()
95
103
process!! .inputStream.bufferedReader().use { reader ->
0 commit comments