mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-27 22:07:33 +08:00
A pull mirror copied its newest branch tip's committer date into the repository's "Last updated" field. Commit dates are set by whoever made the commit, so a single tip dated 2098 kept an idle mirror at the top of Explore for decades. Like GitHub, GitLab and Gitea's own push handling, a sync now sets the update time to the sync time when any ref changed and leaves it untouched otherwise. Fixes: https://github.com/go-gitea/gitea/issues/40480 Assisted-by: Codex:GPT-6 Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: silverwind <me@silverwind.io>
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"gitea.dev/modules/git/gitcmd"
|
|
)
|
|
|
|
// CommitsCountOptions the options when counting commits
|
|
type CommitsCountOptions struct {
|
|
Not string
|
|
Revision []string
|
|
RelPath []string
|
|
Since string
|
|
Until string
|
|
}
|
|
|
|
// CommitsCount returns number of total commits of until given revision.
|
|
func CommitsCount(ctx context.Context, repo RepositoryFacade, opts CommitsCountOptions) (int64, error) {
|
|
cmd := gitcmd.NewCommand("rev-list", "--count")
|
|
|
|
cmd.AddDynamicArguments(opts.Revision...)
|
|
|
|
if opts.Not != "" {
|
|
cmd.AddOptionValues("--not", opts.Not)
|
|
}
|
|
|
|
if opts.Since != "" {
|
|
cmd.AddOptionFormat("--since=%s", opts.Since)
|
|
}
|
|
|
|
if opts.Until != "" {
|
|
cmd.AddOptionFormat("--until=%s", opts.Until)
|
|
}
|
|
|
|
if len(opts.RelPath) > 0 {
|
|
cmd.AddDashesAndList(opts.RelPath...)
|
|
}
|
|
|
|
stdout, _, err := cmd.WithRepo(repo).RunStdString(ctx)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
|
|
}
|
|
|
|
// FileCommitsCount return the number of files at a revision
|
|
func FileCommitsCount(ctx context.Context, repo RepositoryFacade, revision, file string) (int64, error) {
|
|
return CommitsCount(ctx, repo,
|
|
CommitsCountOptions{
|
|
Revision: []string{revision},
|
|
RelPath: []string{file},
|
|
})
|
|
}
|
|
|
|
// CommitsCountOfCommit returns number of total commits of until current revision.
|
|
func CommitsCountOfCommit(ctx context.Context, repo RepositoryFacade, commitID string) (int64, error) {
|
|
return CommitsCount(ctx, repo, CommitsCountOptions{
|
|
Revision: []string{commitID},
|
|
})
|
|
}
|
|
|
|
// AllCommitsCount returns count of all commits in repository
|
|
func AllCommitsCount(ctx context.Context, repo RepositoryFacade, hidePRRefs bool, files ...string) (int64, error) {
|
|
cmd := gitcmd.NewCommand("rev-list")
|
|
if hidePRRefs {
|
|
cmd.AddArguments("--exclude=" + PullPrefix + "*")
|
|
}
|
|
cmd.AddArguments("--all", "--count")
|
|
if len(files) > 0 {
|
|
cmd.AddDashesAndList(files...)
|
|
}
|
|
|
|
stdout, _, err := cmd.WithRepo(repo).RunStdString(ctx)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
|
|
}
|