Skip to content

Commit db93fa5

Browse files
committed
gogs/gogs#2586 better approach to prevent iterate all commits
1 parent 1b71bff commit db93fa5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.3.1"
13+
const _VERSION = "0.3.2"
1414

1515
func Version() string {
1616
return _VERSION

repo_commit.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"fmt"
1111
"strconv"
1212
"strings"
13+
14+
"github.com/mcuadros/go-version"
1315
)
1416

1517
// getRefCommitID returns the last commit ID string of given reference (branch or tag).
@@ -223,7 +225,18 @@ func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (in
223225
return len(strings.Split(stdout, "\n")) - 1, nil
224226
}
225227

228+
// CommitsBetween returns a list that contains commits between [last, before).
226229
func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) {
230+
if version.Compare(gitVersion, "1.8.0", ">=") {
231+
stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path)
232+
if err != nil {
233+
return nil, err
234+
}
235+
return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout))
236+
}
237+
238+
// Fallback to stupid solution, which iterates all commits of the repository
239+
// if before is not an ancestor of last.
227240
l := list.New()
228241
if last == nil || last.ParentCount() == 0 {
229242
return l, nil

0 commit comments

Comments
 (0)