mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Pass 'not' to commit count (#24473)
Due to #24409 , we can now specify '--not' when getting all commits from a repo to exclude commits from a different branch. When I wrote that PR, I forgot to also update the code that counts the number of commits in the repo. So now, if the --not option is used, it may return too many commits, which can indicate that another page of data is available when it is not. This PR passes --not to the commands that count the number of commits in a repo
This commit is contained in:
		| @@ -160,15 +160,29 @@ func AllCommitsCount(ctx context.Context, repoPath string, hidePRRefs bool, file | ||||
| 	return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) | ||||
| } | ||||
|  | ||||
| // CommitsCountFiles returns number of total commits of until given revision. | ||||
| func CommitsCountFiles(ctx context.Context, repoPath string, revision, relpath []string) (int64, error) { | ||||
| // CommitsCountOptions the options when counting commits | ||||
| type CommitsCountOptions struct { | ||||
| 	RepoPath string | ||||
| 	Not      string | ||||
| 	Revision []string | ||||
| 	RelPath  []string | ||||
| } | ||||
|  | ||||
| // CommitsCount returns number of total commits of until given revision. | ||||
| func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) { | ||||
| 	cmd := NewCommand(ctx, "rev-list", "--count") | ||||
| 	cmd.AddDynamicArguments(revision...) | ||||
| 	if len(relpath) > 0 { | ||||
| 		cmd.AddDashesAndList(relpath...) | ||||
|  | ||||
| 	cmd.AddDynamicArguments(opts.Revision...) | ||||
|  | ||||
| 	if opts.Not != "" { | ||||
| 		cmd.AddOptionValues("--not", opts.Not) | ||||
| 	} | ||||
|  | ||||
| 	stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath}) | ||||
| 	if len(opts.RelPath) > 0 { | ||||
| 		cmd.AddDashesAndList(opts.RelPath...) | ||||
| 	} | ||||
|  | ||||
| 	stdout, _, err := cmd.RunStdString(&RunOpts{Dir: opts.RepoPath}) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| @@ -176,14 +190,12 @@ func CommitsCountFiles(ctx context.Context, repoPath string, revision, relpath [ | ||||
| 	return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) | ||||
| } | ||||
|  | ||||
| // CommitsCount returns number of total commits of until given revision. | ||||
| func CommitsCount(ctx context.Context, repoPath string, revision ...string) (int64, error) { | ||||
| 	return CommitsCountFiles(ctx, repoPath, revision, []string{}) | ||||
| } | ||||
|  | ||||
| // CommitsCount returns number of total commits of until current revision. | ||||
| func (c *Commit) CommitsCount() (int64, error) { | ||||
| 	return CommitsCount(c.repo.Ctx, c.repo.Path, c.ID.String()) | ||||
| 	return CommitsCount(c.repo.Ctx, CommitsCountOptions{ | ||||
| 		RepoPath: c.repo.Path, | ||||
| 		Revision: []string{c.ID.String()}, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| // CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize | ||||
|   | ||||
		Reference in New Issue
	
	Block a user