Skip to content

Commit 511f613

Browse files
zeripath6543techknowlogick
authored
Use native git variants by default with go-git variants as build tag (#13673)
* Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <[email protected]> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <[email protected]> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <[email protected]> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <[email protected]> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <[email protected]> * Make no-go-git variants Signed-off-by: Andrew Thornton <[email protected]> * Submodule RefID Signed-off-by: Andrew Thornton <[email protected]> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <[email protected]> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <[email protected]> * Improve efficiency Signed-off-by: Andrew Thornton <[email protected]> * More efficiency Signed-off-by: Andrew Thornton <[email protected]> * even faster Signed-off-by: Andrew Thornton <[email protected]> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <[email protected]> * attempt to fix drone Signed-off-by: Andrew Thornton <[email protected]> * fix test-tags Signed-off-by: Andrew Thornton <[email protected]> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <[email protected]> * placate lint Signed-off-by: Andrew Thornton <[email protected]> * as per @6543 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 0851a89 commit 511f613

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3952
-1492
lines changed

.drone.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ steps:
3333
GOSUMDB: sum.golang.org
3434
TAGS: bindata sqlite sqlite_unlock_notify
3535

36+
- name: lint-backend-gogit
37+
pull: always
38+
image: golang:1.15
39+
commands:
40+
- make lint-backend
41+
environment:
42+
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
43+
GOSUMDB: sum.golang.org
44+
TAGS: bindata gogit sqlite sqlite_unlock_notify
45+
3646
- name: checks-frontend
3747
image: node:14
3848
commands:
@@ -69,7 +79,7 @@ steps:
6979
GOPROXY: off
7080
GOOS: linux
7181
GOARCH: arm64
72-
TAGS: bindata
82+
TAGS: bindata gogit
7383
commands:
7484
- make backend # test cross compile
7585
- rm ./gitea # clean
@@ -173,6 +183,17 @@ steps:
173183
GITHUB_READ_TOKEN:
174184
from_secret: github_read_token
175185

186+
- name: unit-test-gogit
187+
pull: always
188+
image: golang:1.15
189+
commands:
190+
- make unit-test-coverage test-check
191+
environment:
192+
GOPROXY: off
193+
TAGS: bindata gogit sqlite sqlite_unlock_notify
194+
GITHUB_READ_TOKEN:
195+
from_secret: github_read_token
196+
176197
- name: test-mysql
177198
image: golang:1.15
178199
commands:
@@ -305,7 +326,8 @@ steps:
305326
- timeout -s ABRT 40m make test-sqlite-migration test-sqlite
306327
environment:
307328
GOPROXY: off
308-
TAGS: bindata
329+
TAGS: bindata gogit sqlite sqlite_unlock_notify
330+
TEST_TAGS: gogit sqlite sqlite_unlock_notify
309331
USE_REPO_TEST_DIR: 1
310332
depends_on:
311333
- build
@@ -318,7 +340,8 @@ steps:
318340
- timeout -s ABRT 40m make test-pgsql-migration test-pgsql
319341
environment:
320342
GOPROXY: off
321-
TAGS: bindata
343+
TAGS: bindata gogit
344+
TEST_TAGS: gogit
322345
TEST_LDAP: 1
323346
USE_REPO_TEST_DIR: 1
324347
depends_on:

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ TAGS ?=
110110
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
111111
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
112112

113+
TEST_TAGS ?= sqlite sqlite_unlock_notify
114+
113115
GO_DIRS := cmd integrations models modules routers build services vendor tools
116+
114117
GO_SOURCES := $(wildcard *.go)
115118
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)
116119

@@ -339,8 +342,8 @@ watch-backend: go-check
339342

340343
.PHONY: test
341344
test:
342-
@echo "Running go test..."
343-
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' $(GO_PACKAGES)
345+
@echo "Running go test with -tags '$(TEST_TAGS)'..."
346+
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' $(GO_PACKAGES)
344347

345348
.PHONY: test-check
346349
test-check:
@@ -356,17 +359,17 @@ test-check:
356359

357360
.PHONY: test\#%
358361
test\#%:
359-
@echo "Running go test..."
360-
@$(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $(subst .,/,$*) $(GO_PACKAGES)
362+
@echo "Running go test with -tags '$(TEST_TAGS)'..."
363+
@$(GO) test -mod=vendor -tags='$(TEST_TAGS)' -run $(subst .,/,$*) $(GO_PACKAGES)
361364

362365
.PHONY: coverage
363366
coverage:
364367
GO111MODULE=on $(GO) run -mod=vendor build/gocovmerge.go integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all
365368

366369
.PHONY: unit-test-coverage
367370
unit-test-coverage:
368-
@echo "Running unit-test-coverage..."
369-
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
371+
@echo "Running unit-test-coverage -tags '$(TEST_TAGS)'..."
372+
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
370373

371374
.PHONY: vendor
372375
vendor:
@@ -511,7 +514,7 @@ integrations.mssql.test: git-check $(GO_SOURCES)
511514
$(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
512515

513516
integrations.sqlite.test: git-check $(GO_SOURCES)
514-
$(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
517+
$(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags '$(TEST_TAGS)'
515518

516519
integrations.cover.test: git-check $(GO_SOURCES)
517520
$(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(GO_PACKAGES) | tr ' ' ',') -o integrations.cover.test
@@ -534,7 +537,7 @@ migrations.mssql.test: $(GO_SOURCES)
534537

535538
.PHONY: migrations.sqlite.test
536539
migrations.sqlite.test: $(GO_SOURCES)
537-
$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
540+
$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags '$(TEST_TAGS)'
538541

539542
.PHONY: check
540543
check: test

docs/content/doc/installation/from-source.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Depending on requirements, the following build tags can be included.
101101
- `pam`: Enable support for PAM (Linux Pluggable Authentication Modules). Can
102102
be used to authenticate local users or extend authentication to methods
103103
available to PAM.
104+
* `gogit`: (EXPERIMENTAL) Use go-git variants of git commands.
104105

105106
Bundling assets into the binary using the `bindata` build tag is recommended for
106107
production deployments. It is possible to serve the static assets directly via a reverse proxy,

modules/cache/cache.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ func newCache(cacheConfig setting.Cache) (mc.Cache, error) {
2727
})
2828
}
2929

30+
// Cache is the interface that operates the cache data.
31+
type Cache interface {
32+
// Put puts value into cache with key and expire time.
33+
Put(key string, val interface{}, timeout int64) error
34+
// Get gets cached value by given key.
35+
Get(key string) interface{}
36+
// Delete deletes cached value by given key.
37+
Delete(key string) error
38+
// Incr increases cached int-type value by given key as a counter.
39+
Incr(key string) error
40+
// Decr decreases cached int-type value by given key as a counter.
41+
Decr(key string) error
42+
// IsExist returns true if cached value exists.
43+
IsExist(key string) bool
44+
// Flush deletes all cached data.
45+
Flush() error
46+
}
47+
3048
// NewContext start cache service
3149
func NewContext() error {
3250
var err error
@@ -40,6 +58,11 @@ func NewContext() error {
4058
return err
4159
}
4260

61+
// GetCache returns the currently configured cache
62+
func GetCache() Cache {
63+
return conn
64+
}
65+
4366
// GetString returns the key value from cache with callback when no key exists in cache
4467
func GetString(key string, getFunc func() (string, error)) (string, error) {
4568
if conn == nil || setting.CacheService.TTL == 0 {

modules/cache/last_commit.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

modules/convert/git_commit_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import (
1313
api "code.gitea.io/gitea/modules/structs"
1414
"code.gitea.io/gitea/modules/util"
1515

16-
"github.com/go-git/go-git/v5/plumbing/object"
1716
"github.com/stretchr/testify/assert"
1817
)
1918

2019
func TestToCommitMeta(t *testing.T) {
2120
assert.NoError(t, models.PrepareTestDatabase())
2221
headRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
2322
sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
24-
signature := &object.Signature{Name: "Test Signature", Email: "[email protected]", When: time.Unix(0, 0)}
23+
signature := &git.Signature{Name: "Test Signature", Email: "[email protected]", When: time.Unix(0, 0)}
2524
tag := &git.Tag{
2625
Name: "Test Tag",
2726
ID: sha1,

0 commit comments

Comments
 (0)