Browse Source

Merge branch 'V20211213' into zhou

pull/1106/head
zhoupzh 3 years ago
parent
commit
e1f9b260a8
4 changed files with 16 additions and 3 deletions
  1. +9
    -0
      modules/git/commit.go
  2. +4
    -0
      modules/git/repo.go
  3. +2
    -2
      modules/git/repo_stats_custom.go
  4. +1
    -1
      routers/private/hook.go

+ 9
- 0
modules/git/commit.go View File

@@ -271,6 +271,15 @@ func AllCommitsCount(repoPath string) (int64, error) {
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) {
cmd := NewCommand("rev-list", "--count")
cmd.AddArguments(revision)


+ 4
- 0
modules/git/repo.go View File

@@ -52,6 +52,10 @@ func (repo *Repository) GetAllCommitsCount() (int64, error) {
return AllCommitsCount(repo.Path)
}

func (repo *Repository) GetHeadCommitsCount() (int64, error) {
return HEADCommitsCount(repo.Path)
}

func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) {
l := list.New()
if len(logs) == 0 {


+ 2
- 2
modules/git/repo_stats_custom.go View File

@@ -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 {
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)
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) {
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)
if err != nil {
return nil, err


+ 1
- 1
routers/private/hook.go View File

@@ -539,7 +539,7 @@ func updateRepoCommitCnt(ctx *macaron.Context, repo *models.Repository) error {
}
defer gitRepo.Close()

count, err := gitRepo.GetAllCommitsCount()
count, err := gitRepo.GetHeadCommitsCount()
if err != nil {
log.Error("GetAllCommitsCount failed:%v", err.Error(), ctx.Data["MsgID"])
return err


Loading…
Cancel
Save