11package com.huayi.intellijplatform.gitstats.utils
22
3+ import git4idea.config.GitExecutableManager
34import java.util.concurrent.TimeUnit
5+ import com.intellij.openapi.project.Project
46
57data class UserStats (
68 val author : String ,
@@ -24,7 +26,15 @@ data class CommitFilesStats(
2426 var addedLines : Int = 0 , var deletedLines : Int = 0 , var fileName : String
2527)
2628
27- class GitUtil (private val repoPath : String ) {
29+ class GitUtils (project : Project ) {
30+ private val gitExecutablePath: String = GitExecutableManager .getInstance().getExecutable(project).exePath
31+ private val basePath: String = project.basePath as String
32+
33+ // companion object {
34+ // fun getGitExecutablePath(project: Project): String {
35+ // return GitExecutableManager.getInstance().getExecutable(project).exePath
36+ // }
37+ // }
2838
2939 fun getTopSpeedUserStats (
3040 startDate : String , endDate : String , timeoutAmount : Long = 60L, timeUnit : TimeUnit = TimeUnit .SECONDS
@@ -33,9 +43,9 @@ class GitUtil(private val repoPath: String) {
3343 val command = listOf (
3444 if (os == " Windows" ) " cmd" else " /bin/sh" ,
3545 if (os == " Windows" ) " /c" else " -c" ,
36- " 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"
46+ " $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"
3747 )
38- val process = Utils .runCommand(repoPath , command, timeoutAmount, timeUnit)
48+ val process = Utils .runCommand(basePath , command, timeoutAmount, timeUnit)
3949 val regex = Regex (" (.+)\\ n+added lines: (\\ d*), removed lines: (\\ d+), modified files: (\\ d+)" )
4050 return regex.findAll(process!! .inputStream.bufferedReader().readText())
4151 .map { result ->
@@ -61,7 +71,7 @@ class GitUtil(private val repoPath: String) {
6171 " --until=$endDate "
6272 )
6373
64- val process = Utils .runCommand(repoPath , gitCommand, timeoutAmount, timeUnit)
74+ val process = Utils .runCommand(basePath , gitCommand, timeoutAmount, timeUnit)
6575
6676 val userStatsData = mutableMapOf<String , UserStats >()
6777 process!! .inputStream.bufferedReader().use { reader ->
0 commit comments