Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 576fbdd

Browse files
daviianbkcsoft
authored andcommitted
remove unnecessary version checks
Signed-off-by: David Schneiderbauer <[email protected]>
1 parent cdf53e0 commit 576fbdd

File tree

3 files changed

+5
-50
lines changed

3 files changed

+5
-50
lines changed

commit.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"net/http"
1313
"strconv"
1414
"strings"
15-
16-
"github.com/mcuadros/go-version"
1715
)
1816

1917
// Commit represents a git commit.
@@ -160,13 +158,7 @@ func CommitChanges(repoPath string, opts CommitChangesOptions) error {
160158

161159
func commitsCount(repoPath, revision, relpath string) (int64, error) {
162160
var cmd *Command
163-
isFallback := false
164-
if version.Compare(gitVersion, "1.8.0", "<") {
165-
isFallback = true
166-
cmd = NewCommand("log", "--pretty=format:''")
167-
} else {
168-
cmd = NewCommand("rev-list", "--count")
169-
}
161+
cmd = NewCommand("rev-list", "--count")
170162
cmd.AddArguments(revision)
171163
if len(relpath) > 0 {
172164
cmd.AddArguments("--", relpath)
@@ -177,9 +169,6 @@ func commitsCount(repoPath, revision, relpath string) (int64, error) {
177169
return 0, err
178170
}
179171

180-
if isFallback {
181-
return int64(strings.Count(stdout, "\n")) + 1, nil
182-
}
183172
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
184173
}
185174

repo_branch.go

-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ package git
77
import (
88
"fmt"
99
"strings"
10-
11-
"github.com/mcuadros/go-version"
1210
)
1311

1412
// BranchPrefix base dir of the branch information file store on git
@@ -56,10 +54,6 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) {
5654

5755
// SetDefaultBranch sets default branch of repository.
5856
func (repo *Repository) SetDefaultBranch(name string) error {
59-
if version.Compare(gitVersion, "1.7.10", "<") {
60-
return ErrUnsupportedVersion{"1.7.10"}
61-
}
62-
6357
_, err := NewCommand("symbolic-ref", "HEAD", BranchPrefix+name).RunInDir(repo.Path)
6458
return err
6559
}

repo_commit.go

+4-32
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"fmt"
1111
"strconv"
1212
"strings"
13-
14-
"github.com/mcuadros/go-version"
1513
)
1614

1715
// getRefCommitID returns the last commit ID string of given reference (branch or tag).
@@ -248,37 +246,11 @@ func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (in
248246

249247
// CommitsBetween returns a list that contains commits between [last, before).
250248
func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) {
251-
if version.Compare(gitVersion, "1.8.0", ">=") {
252-
stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path)
253-
if err != nil {
254-
return nil, err
255-
}
256-
return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout))
257-
}
258-
259-
// Fallback to stupid solution, which iterates all commits of the repository
260-
// if before is not an ancestor of last.
261-
l := list.New()
262-
if last == nil || last.ParentCount() == 0 {
263-
return l, nil
264-
}
265-
266-
var err error
267-
cur := last
268-
for {
269-
if cur.ID.Equal(before.ID) {
270-
break
271-
}
272-
l.PushBack(cur)
273-
if cur.ParentCount() == 0 {
274-
break
275-
}
276-
cur, err = cur.Parent(0)
277-
if err != nil {
278-
return nil, err
279-
}
249+
stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path)
250+
if err != nil {
251+
return nil, err
280252
}
281-
return l, nil
253+
return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout))
282254
}
283255

284256
// CommitsBetweenIDs return commits between twoe commits

0 commit comments

Comments
 (0)