Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/1104 Reviewed-by: lewis <747342561@qq.com>tags/v1.21.12.1^2
| @@ -271,6 +271,15 @@ func AllCommitsCount(repoPath string) (int64, error) { | |||||
| return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) | return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) | ||||
| } | } | ||||
| func HEADCommitsCount(repoPath string) (int64, error) { | |||||
| stdout, err := NewCommand("rev-list", "HEAD", "--count").RunInDir(repoPath) | |||||
| if err != nil { | |||||
| return 0, err | |||||
| } | |||||
| return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) | |||||
| } | |||||
| func commitsCount(repoPath, revision, relpath string) (int64, error) { | func commitsCount(repoPath, revision, relpath string) (int64, error) { | ||||
| cmd := NewCommand("rev-list", "--count") | cmd := NewCommand("rev-list", "--count") | ||||
| cmd.AddArguments(revision) | cmd.AddArguments(revision) | ||||
| @@ -52,6 +52,10 @@ func (repo *Repository) GetAllCommitsCount() (int64, error) { | |||||
| return AllCommitsCount(repo.Path) | return AllCommitsCount(repo.Path) | ||||
| } | } | ||||
| func (repo *Repository) GetHeadCommitsCount() (int64, error) { | |||||
| return HEADCommitsCount(repo.Path) | |||||
| } | |||||
| func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { | func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { | ||||
| l := list.New() | l := list.New() | ||||
| if len(logs) == 0 { | if len(logs) == 0 { | ||||
| @@ -126,7 +126,7 @@ func GetUserKPIStats(repoPath string) (map[string]*UserKPIStats, error) { | |||||
| func SetRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, newContributers map[string]struct{}) error { | func SetRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, newContributers map[string]struct{}) error { | ||||
| since := fromTime.Format(time.RFC3339) | since := fromTime.Format(time.RFC3339) | ||||
| args := []string{"log", "--numstat", "--no-merges", "--branches=*", "--pretty=format:---%n%h%n%an%n%ae%n", "--date=iso", fmt.Sprintf("--since='%s'", since)} | |||||
| args := []string{"log", "--numstat", "--no-merges", "HEAD", "--pretty=format:---%n%h%n%an%n%ae%n", "--date=iso", fmt.Sprintf("--since='%s'", since)} | |||||
| stdout, err := NewCommand(args...).RunInDirBytes(repoPath) | stdout, err := NewCommand(args...).RunInDirBytes(repoPath) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -212,7 +212,7 @@ func SetRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, n | |||||
| func GetContributorsDetail(repoPath string, fromTime time.Time) ([]Contributor, error) { | func GetContributorsDetail(repoPath string, fromTime time.Time) ([]Contributor, error) { | ||||
| since := fromTime.Format(time.RFC3339) | since := fromTime.Format(time.RFC3339) | ||||
| cmd := NewCommand("shortlog", "-sne", "--all", fmt.Sprintf("--since='%s'", since)) | |||||
| cmd := NewCommand("shortlog", "-sne", "HEAD", fmt.Sprintf("--since='%s'", since)) | |||||
| stdout, err := cmd.RunInDir(repoPath) | stdout, err := cmd.RunInDir(repoPath) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| @@ -539,7 +539,7 @@ func updateRepoCommitCnt(ctx *macaron.Context, repo *models.Repository) error { | |||||
| } | } | ||||
| defer gitRepo.Close() | defer gitRepo.Close() | ||||
| count, err := gitRepo.GetAllCommitsCount() | |||||
| count, err := gitRepo.GetHeadCommitsCount() | |||||
| if err != nil { | if err != nil { | ||||
| log.Error("GetAllCommitsCount failed:%v", err.Error(), ctx.Data["MsgID"]) | log.Error("GetAllCommitsCount failed:%v", err.Error(), ctx.Data["MsgID"]) | ||||
| return err | return err | ||||