Skip to content

Commit 300d5cc

Browse files
committed
Enable Go modules
1 parent 9f607e8 commit 300d5cc

File tree

9 files changed

+57
-23
lines changed

9 files changed

+57
-23
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ go:
66
- 1.6.x
77
- 1.7.x
88
- 1.8.x
9-
- master
9+
- 1.9.x
10+
- 1.10.x
11+
- 1.11.x
12+
- 1.12.x
1013

1114
script:
1215
- go get golang.org/x/tools/cmd/cover

commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strconv"
1515
"strings"
1616

17-
"github.com/mcuadros/go-version"
17+
goversion "github.com/mcuadros/go-version"
1818
)
1919

2020
// Commit represents a git commit.
@@ -141,7 +141,7 @@ func CommitChanges(repoPath string, opts CommitChangesOptions) error {
141141
func commitsCount(repoPath, revision, relpath string) (int64, error) {
142142
var cmd *Command
143143
isFallback := false
144-
if version.Compare(gitVersion, "1.8.0", "<") {
144+
if goversion.Compare(gitVersion, "1.8.0", "<") {
145145
isFallback = true
146146
cmd = NewCommand("log", "--pretty=format:''")
147147
} else {

git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.7.1"
13+
const version = "0.8.0"
1414

1515
func Version() string {
16-
return _VERSION
16+
return version
1717
}
1818

1919
var (

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/gogs/git-module
2+
3+
go 1.12
4+
5+
require (
6+
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
7+
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75
8+
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
9+
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337
10+
)

go.sum

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
2+
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
3+
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
4+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
5+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
6+
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 h1:Pijfgr7ZuvX7QIQiEwLdRVr3RoMG+i0SbBO1Qu+7yVk=
7+
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo=
8+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
9+
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY=
10+
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
11+
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8=
12+
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
13+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
14+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
15+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
16+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
17+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

repo.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import (
1111
"os"
1212
"path"
1313
"path/filepath"
14+
"strconv"
1415
"strings"
1516
"time"
16-
17-
"github.com/unknwon/com"
1817
)
1918

2019
// Repository represents a Git repository.
@@ -251,6 +250,11 @@ const (
251250
_STAT_SIZE_GARBAGE = "size-garbage: "
252251
)
253252

253+
func strToInt64(s string) int64 {
254+
i, _ := strconv.ParseInt(s, 10, 64)
255+
return i
256+
}
257+
254258
// GetRepoSize returns disk usage report of repository in given path.
255259
func GetRepoSize(repoPath string) (*CountObject, error) {
256260
cmd := NewCommand("count-objects", "-v")
@@ -263,21 +267,21 @@ func GetRepoSize(repoPath string) (*CountObject, error) {
263267
for _, line := range strings.Split(stdout, "\n") {
264268
switch {
265269
case strings.HasPrefix(line, _STAT_COUNT):
266-
countObject.Count = com.StrTo(line[7:]).MustInt64()
270+
countObject.Count = strToInt64(line[7:])
267271
case strings.HasPrefix(line, _STAT_SIZE):
268-
countObject.Size = com.StrTo(line[6:]).MustInt64() * 1024
272+
countObject.Size = strToInt64(line[6:]) * 1024
269273
case strings.HasPrefix(line, _STAT_IN_PACK):
270-
countObject.InPack = com.StrTo(line[9:]).MustInt64()
274+
countObject.InPack = strToInt64(line[9:])
271275
case strings.HasPrefix(line, _STAT_PACKS):
272-
countObject.Packs = com.StrTo(line[7:]).MustInt64()
276+
countObject.Packs = strToInt64(line[7:])
273277
case strings.HasPrefix(line, _STAT_SIZE_PACK):
274-
countObject.SizePack = com.StrTo(line[11:]).MustInt64() * 1024
278+
countObject.SizePack = strToInt64(line[11:]) * 1024
275279
case strings.HasPrefix(line, _STAT_PRUNE_PACKABLE):
276-
countObject.PrunePackable = com.StrTo(line[16:]).MustInt64()
280+
countObject.PrunePackable = strToInt64(line[16:])
277281
case strings.HasPrefix(line, _STAT_GARBAGE):
278-
countObject.Garbage = com.StrTo(line[9:]).MustInt64()
282+
countObject.Garbage = strToInt64(line[9:])
279283
case strings.HasPrefix(line, _STAT_SIZE_GARBAGE):
280-
countObject.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024
284+
countObject.SizeGarbage = strToInt64(line[14:]) * 1024
281285
}
282286
}
283287

repo_branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"strings"
1010

11-
"github.com/mcuadros/go-version"
11+
goversion "github.com/mcuadros/go-version"
1212
)
1313

1414
const BRANCH_PREFIX = "refs/heads/"
@@ -54,7 +54,7 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) {
5454

5555
// SetDefaultBranch sets default branch of repository.
5656
func (repo *Repository) SetDefaultBranch(name string) error {
57-
if version.Compare(gitVersion, "1.7.10", "<") {
57+
if goversion.Compare(gitVersion, "1.7.10", "<") {
5858
return ErrUnsupportedVersion{"1.7.10"}
5959
}
6060

repo_commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"time"
1414

15-
"github.com/mcuadros/go-version"
15+
goversion "github.com/mcuadros/go-version"
1616
)
1717

1818
const REMOTE_PREFIX = "refs/remotes/"
@@ -257,7 +257,7 @@ func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (in
257257

258258
// CommitsBetween returns a list that contains commits between [last, before).
259259
func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) {
260-
if version.Compare(gitVersion, "1.8.0", ">=") {
260+
if goversion.Compare(gitVersion, "1.8.0", ">=") {
261261
stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path)
262262
if err != nil {
263263
return nil, err

repo_tag.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"strings"
1010

11-
"github.com/mcuadros/go-version"
11+
goversion "github.com/mcuadros/go-version"
1212
)
1313

1414
const TAG_PREFIX = "refs/tags/"
@@ -95,7 +95,7 @@ func (repo *Repository) GetTag(name string) (*Tag, error) {
9595
// GetTags returns all tags of the repository.
9696
func (repo *Repository) GetTags() ([]string, error) {
9797
cmd := NewCommand("tag", "-l")
98-
if version.Compare(gitVersion, "2.4.9", ">=") {
98+
if goversion.Compare(gitVersion, "2.4.9", ">=") {
9999
cmd.AddArguments("--sort=-creatordate")
100100
}
101101

@@ -107,8 +107,8 @@ func (repo *Repository) GetTags() ([]string, error) {
107107
tags := strings.Split(stdout, "\n")
108108
tags = tags[:len(tags)-1]
109109

110-
if version.Compare(gitVersion, "2.4.9", "<") {
111-
version.Sort(tags)
110+
if goversion.Compare(gitVersion, "2.4.9", "<") {
111+
goversion.Sort(tags)
112112

113113
// Reverse order
114114
for i := 0; i < len(tags)/2; i++ {

0 commit comments

Comments
 (0)