Skip to content

Commit b06488e

Browse files
authored
ci: set up Codecov (#45)
* ci: set up Codecov * commit: add more tests * repo_commit: improve cache hit rate * commit: add more tests * commit: add more tests * commit: finish all tests
1 parent e681e9f commit b06488e

File tree

7 files changed

+592
-34
lines changed

7 files changed

+592
-34
lines changed

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ go:
66
- 1.11.x
77
- 1.12.x
88
- 1.13.x
9+
go_import_path: github.com/gogs/git-module
10+
11+
env:
12+
- GO111MODULE=on
13+
14+
install:
15+
- go get -t -v ./...
916

10-
install: go get -v -t ./...
1117
script:
12-
- go test -v -cover -race -verbose
18+
- go test -v -race -verbose -coverprofile=coverage.txt -covermode=atomic
19+
20+
after_success:
21+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Git Module
22

3-
[![Build Status](https://img.shields.io/travis/gogs/git-module/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.org/gogs/git-module) [![Build status](https://img.shields.io/appveyor/ci/unknwon/gogs-git-module?logo=appveyor&style=for-the-badge)](https://ci.appveyor.com/project/unknwon/gogs-git-module/branch/master) [![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/gogs/git-module)
3+
[![Build Status](https://img.shields.io/travis/gogs/git-module/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.org/gogs/git-module) [![Build status](https://img.shields.io/appveyor/ci/unknwon/gogs-git-module?logo=appveyor&style=for-the-badge)](https://ci.appveyor.com/project/unknwon/gogs-git-module/branch/master) [![codecov](https://img.shields.io/codecov/c/github/gogs/git-module/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/gogs/git-module) [![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/gogs/git-module)
44

55
Package git-module is a Go module for Git access through shell commands.
66

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
comment:
2+
layout: 'diff, files'

commit.go

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package git
66

77
import (
8+
"bytes"
9+
"io"
10+
"io/ioutil"
811
"net/http"
912
"strings"
1013
"sync"
@@ -103,9 +106,9 @@ func (c *Commit) CommitsCount(opts ...RevListCountOptions) (int64, error) {
103106
return c.repo.RevListCount([]string{c.id.String()}, opts...)
104107
}
105108

106-
// FilesChangedSince returns a list of files changed since given commit ID.
107-
func (c *Commit) FilesChangedSince(commitID string, opts ...DiffNameOnlyOptions) ([]string, error) {
108-
return c.repo.DiffNameOnly(commitID, c.id.String(), opts...)
109+
// FilesChangedSince returns a list of files changed after given commit ID.
110+
func (c *Commit) FilesChangedAfter(after string, opts ...DiffNameOnlyOptions) ([]string, error) {
111+
return c.repo.DiffNameOnly(after, c.id.String(), opts...)
109112
}
110113

111114
// CommitsAfter returns a list of commits after given commit ID up to this commit. The returned
@@ -116,28 +119,59 @@ func (c *Commit) CommitsAfter(after string, opts ...RevListOptions) ([]*Commit,
116119

117120
// Ancestors returns a list of ancestors of this commit in reverse chronological order.
118121
func (c *Commit) Ancestors(opts ...LogOptions) ([]*Commit, error) {
119-
return c.repo.Log(c.id.String(), opts...)
122+
if c.ParentsCount() == 0 {
123+
return []*Commit{}, nil
124+
}
125+
126+
var opt LogOptions
127+
if len(opts) > 0 {
128+
opt = opts[0]
129+
}
130+
131+
opt.Skip++
132+
133+
return c.repo.Log(c.id.String(), opt)
134+
}
135+
136+
type limitWriter struct {
137+
W io.Writer
138+
N int64
120139
}
121140

122-
func isImageFile(data []byte) (string, bool) {
123-
contentType := http.DetectContentType(data)
124-
if strings.Contains(contentType, "image/") {
125-
return contentType, true
141+
func (w *limitWriter) Write(p []byte) (int, error) {
142+
if w.N <= 0 {
143+
return len(p), nil
126144
}
127-
return contentType, false
145+
146+
limit := int64(len(p))
147+
if limit > w.N {
148+
limit = w.N
149+
}
150+
n, err := w.W.Write(p[:limit])
151+
w.N -= int64(n)
152+
153+
// Prevent "short write" error
154+
return len(p), err
128155
}
129156

130-
// IsImageFile returns true if the commit is a image blob.
131-
func (c *Commit) IsImageFile(name string) bool {
157+
// IsImageFile returns true if the commit is an image blob.
158+
func (c *Commit) IsImageFile(name string) (bool, error) {
132159
blob, err := c.Blob(name)
133160
if err != nil {
134-
return false
161+
return false, err
135162
}
136163

137-
p, err := blob.Bytes()
164+
buf := new(bytes.Buffer)
165+
buf.Grow(512)
166+
stdout := &limitWriter{
167+
W: buf,
168+
N: int64(buf.Cap()),
169+
}
170+
171+
err = blob.Pipeline(stdout, ioutil.Discard)
138172
if err != nil {
139-
return false
173+
return false, err
140174
}
141-
_, isImage := isImageFile(p)
142-
return isImage
175+
176+
return strings.Contains(http.DetectContentType(buf.Bytes()), "image/"), nil
143177
}

0 commit comments

Comments
 (0)