Skip to content

Commit 183cde5

Browse files
committed
fix
1 parent 2f89a04 commit 183cde5

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

modules/git/repo.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ type GPGSettings struct {
3131
Format string
3232
}
3333

34-
const PrettyLogFormat = `--pretty=format:%H`
34+
const prettyLogFormat = `--pretty=format:%H`
3535

3636
// GetAllCommitsCount returns count of all commits in repository
3737
func (repo *Repository) GetAllCommitsCount() (int64, error) {
3838
return AllCommitsCount(repo.Ctx, repo.Path, false)
3939
}
4040

41-
func (repo *Repository) ParsePrettyFormatLogToList(logs []byte) ([]*Commit, error) {
41+
func (repo *Repository) ShowPrettyFormatLogToList(ctx context.Context, revisionRange string) ([]*Commit, error) {
42+
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git <command> [<revision>...] -- [<file>...]'
43+
logs, _, err := NewCommand("log").AddArguments(prettyLogFormat).
44+
AddDynamicArguments(revisionRange).AddArguments("--").
45+
RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
46+
if err != nil {
47+
return nil, err
48+
}
4249
return repo.parsePrettyFormatLogToList(logs)
4350
}
4451

modules/git/repo_commit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
5959
relpath = `\` + relpath
6060
}
6161

62-
stdout, _, runErr := NewCommand("log", "-1", PrettyLogFormat).AddDynamicArguments(id.String()).AddDashesAndList(relpath).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
62+
stdout, _, runErr := NewCommand("log", "-1", prettyLogFormat).AddDynamicArguments(id.String()).AddDashesAndList(relpath).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
6363
if runErr != nil {
6464
return nil, runErr
6565
}
@@ -74,7 +74,7 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
7474

7575
// GetCommitByPath returns the last commit of relative path.
7676
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
77-
stdout, _, runErr := NewCommand("log", "-1", PrettyLogFormat).AddDashesAndList(relpath).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
77+
stdout, _, runErr := NewCommand("log", "-1", prettyLogFormat).AddDashesAndList(relpath).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
7878
if runErr != nil {
7979
return nil, runErr
8080
}
@@ -94,7 +94,7 @@ func (repo *Repository) commitsByRangeWithTime(id ObjectID, page, pageSize int,
9494
cmd := NewCommand("log").
9595
AddOptionFormat("--skip=%d", (page-1)*pageSize).
9696
AddOptionFormat("--max-count=%d", pageSize).
97-
AddArguments(PrettyLogFormat).
97+
AddArguments(prettyLogFormat).
9898
AddDynamicArguments(id.String())
9999

100100
if not != "" {
@@ -141,7 +141,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
141141
}
142142

143143
// create new git log command with limit of 100 commits
144-
cmd := NewCommand("log", "-100", PrettyLogFormat).AddDynamicArguments(id.String())
144+
cmd := NewCommand("log", "-100", prettyLogFormat).AddDynamicArguments(id.String())
145145

146146
// pretend that all refs along with HEAD were listed on command line as <commis>
147147
// https://git-scm.com/docs/git-log#Documentation/git-log.txt---all
@@ -175,7 +175,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
175175
// ignore anything not matching a valid sha pattern
176176
if id.Type().IsValid(v) {
177177
// create new git log command with 1 commit limit
178-
hashCmd := NewCommand("log", "-1", PrettyLogFormat)
178+
hashCmd := NewCommand("log", "-1", prettyLogFormat)
179179
// add previous arguments except for --grep and --all
180180
addCommonSearchArgs(hashCmd)
181181
// add keyword as <commit>
@@ -410,7 +410,7 @@ func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) {
410410

411411
// commitsBefore the limit is depth, not total number of returned commits.
412412
func (repo *Repository) commitsBefore(id ObjectID, limit int) ([]*Commit, error) {
413-
cmd := NewCommand("log", PrettyLogFormat)
413+
cmd := NewCommand("log", prettyLogFormat)
414414
if limit > 0 {
415415
cmd.AddOptionFormat("-%d", limit)
416416
}
@@ -536,7 +536,7 @@ func (repo *Repository) AddLastCommitCache(cacheKey, fullName, sha string) error
536536

537537
// GetCommitBranchStart returns the commit where the branch diverged
538538
func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error) {
539-
cmd := NewCommand("log", PrettyLogFormat)
539+
cmd := NewCommand("log", prettyLogFormat)
540540
cmd.AddDynamicArguments(endCommitID)
541541

542542
stdout, _, runErr := cmd.RunStdBytes(repo.Ctx, &RunOpts{

services/pull/compare.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,9 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
6767

6868
// We have a common base - therefore we know that ... should work
6969
if !fileOnly {
70-
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git <command> [<revision>...] -- [<file>...]'
71-
var logs []byte
72-
logs, _, err = git.NewCommand("log").AddArguments(git.PrettyLogFormat).
73-
AddDynamicArguments(baseCommitID+separator+headBranch).AddArguments("--").
74-
RunStdBytes(ctx, &git.RunOpts{Dir: headGitRepo.Path})
70+
compareInfo.Commits, err = headGitRepo.ShowPrettyFormatLogToList(ctx, baseCommitID+separator+headBranch)
7571
if err != nil {
76-
return nil, err
77-
}
78-
compareInfo.Commits, err = headGitRepo.ParsePrettyFormatLogToList(logs)
79-
if err != nil {
80-
return nil, fmt.Errorf("parsePrettyFormatLogToList: %w", err)
72+
return nil, fmt.Errorf("ShowPrettyFormatLogToList: %w", err)
8173
}
8274
} else {
8375
compareInfo.Commits = []*git.Commit{}

0 commit comments

Comments
 (0)