aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-01-20 18:46:10 +0100
committerGitHub <noreply@github.com>2022-01-20 18:46:10 +0100
commit54e9ee37a7a301dbe74d46fd3c87712e6120e9bf (patch)
tree1be12fb072625c1b896b9d72f7912b018aad502b /modules/git
parent1d98d205f5825f40110e6628b61a97c91ac7f72d (diff)
downloadgitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.tar.gz
gitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.zip
format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/command_test.go2
-rw-r--r--modules/git/commit.go2
-rw-r--r--modules/git/commit_info_gogit.go2
-rw-r--r--modules/git/commit_info_nogogit.go2
-rw-r--r--modules/git/commit_info_test.go6
-rw-r--r--modules/git/commit_test.go1
-rw-r--r--modules/git/git.go4
-rw-r--r--modules/git/hook.go8
-rw-r--r--modules/git/last_commit_cache_gogit.go1
-rw-r--r--modules/git/lfs.go4
-rw-r--r--modules/git/parse_nogogit_test.go1
-rw-r--r--modules/git/repo.go4
-rw-r--r--modules/git/repo_attribute.go2
-rw-r--r--modules/git/repo_attribute_test.go4
-rw-r--r--modules/git/repo_commit.go1
-rw-r--r--modules/git/repo_commit_test.go6
-rw-r--r--modules/git/repo_language_stats.go6
-rw-r--r--modules/git/repo_object.go1
-rw-r--r--modules/git/repo_tag.go2
-rw-r--r--modules/git/submodule_test.go2
-rw-r--r--modules/git/tag.go6
-rw-r--r--modules/git/tree_blob_gogit.go2
-rw-r--r--modules/git/tree_entry_mode.go10
23 files changed, 38 insertions, 41 deletions
diff --git a/modules/git/command_test.go b/modules/git/command_test.go
index 58d616a038..4e257178ef 100644
--- a/modules/git/command_test.go
+++ b/modules/git/command_test.go
@@ -14,7 +14,6 @@ import (
)
func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) {
-
maxLoops := 1000
// 'git --version' does not block so it must be finished before the timeout triggered.
@@ -27,7 +26,6 @@ func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) {
}
func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
-
maxLoops := 1000
// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 8a78653553..0ba53897f5 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -36,7 +36,7 @@ type Commit struct {
// CommitGPGSignature represents a git commit signature part.
type CommitGPGSignature struct {
Signature string
- Payload string //TODO check if can be reconstruct from the rest of commit information to not have duplicate data
+ Payload string // TODO check if can be reconstruct from the rest of commit information to not have duplicate data
}
// Message returns the commit message. Same as retrieving CommitMessage directly.
diff --git a/modules/git/commit_info_gogit.go b/modules/git/commit_info_gogit.go
index ccf90fc8c7..ab6e738103 100644
--- a/modules/git/commit_info_gogit.go
+++ b/modules/git/commit_info_gogit.go
@@ -158,7 +158,7 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[
func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*object.Commit, []string, error) {
var unHitEntryPaths []string
- var results = make(map[string]*object.Commit)
+ results := make(map[string]*object.Commit)
for _, p := range paths {
lastCommit, err := cache.Get(commitID, path.Join(treePath, p))
if err != nil {
diff --git a/modules/git/commit_info_nogogit.go b/modules/git/commit_info_nogogit.go
index b58c1885b6..347ad7d059 100644
--- a/modules/git/commit_info_nogogit.go
+++ b/modules/git/commit_info_nogogit.go
@@ -104,7 +104,7 @@ func getLastCommitForPathsByCache(ctx context.Context, commitID, treePath string
defer cancel()
var unHitEntryPaths []string
- var results = make(map[string]*Commit)
+ results := make(map[string]*Commit)
for _, p := range paths {
lastCommit, err := cache.Get(commitID, path.Join(treePath, p), wr, rd)
if err != nil {
diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go
index a4c0483004..4cc207de64 100644
--- a/modules/git/commit_info_test.go
+++ b/modules/git/commit_info_test.go
@@ -16,8 +16,10 @@ import (
"github.com/stretchr/testify/assert"
)
-const testReposDir = "tests/repos/"
-const benchmarkReposDir = "benchmark/repos/"
+const (
+ testReposDir = "tests/repos/"
+ benchmarkReposDir = "benchmark/repos/"
+)
func cloneRepo(url, dir, name string) (string, error) {
repoDir := filepath.Join(dir, name)
diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go
index 2b3365342d..6e9dd34ea7 100644
--- a/modules/git/commit_test.go
+++ b/modules/git/commit_test.go
@@ -234,5 +234,4 @@ func TestParseCommitFileStatus(t *testing.T) {
assert.Equal(t, kase.removed, fileStatus.Removed)
assert.Equal(t, kase.modified, fileStatus.Modified)
}
-
}
diff --git a/modules/git/git.go b/modules/git/git.go
index cca5ce6714..294d33f916 100644
--- a/modules/git/git.go
+++ b/modules/git/git.go
@@ -112,8 +112,8 @@ func SetExecutablePath(path string) error {
// VersionInfo returns git version information
func VersionInfo() string {
- var format = "Git Version: %s"
- var args = []interface{}{gitVersion.Original()}
+ format := "Git Version: %s"
+ args := []interface{}{gitVersion.Original()}
// Since git wire protocol has been released from git v2.18
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
format += ", Wire Protocol %s Enabled"
diff --git a/modules/git/hook.go b/modules/git/hook.go
index ecd2db3cc3..c50f891224 100644
--- a/modules/git/hook.go
+++ b/modules/git/hook.go
@@ -23,10 +23,8 @@ var hookNames = []string{
"post-receive",
}
-var (
- // ErrNotValidHook error when a git hook is not valid
- ErrNotValidHook = errors.New("not a valid Git hook")
-)
+// ErrNotValidHook error when a git hook is not valid
+var ErrNotValidHook = errors.New("not a valid Git hook")
// IsValidHookName returns true if given name is a valid Git hook.
func IsValidHookName(name string) bool {
@@ -142,5 +140,5 @@ func SetUpdateHook(repoPath, content string) (err error) {
if err != nil {
return err
}
- return os.WriteFile(hookPath, []byte(content), 0777)
+ return os.WriteFile(hookPath, []byte(content), 0o777)
}
diff --git a/modules/git/last_commit_cache_gogit.go b/modules/git/last_commit_cache_gogit.go
index b57e9ad11f..06e85a6db2 100644
--- a/modules/git/last_commit_cache_gogit.go
+++ b/modules/git/last_commit_cache_gogit.go
@@ -64,7 +64,6 @@ func (c *LastCommitCache) Get(ref, entryPath string) (interface{}, error) {
// CacheCommit will cache the commit from the gitRepository
func (c *LastCommitCache) CacheCommit(ctx context.Context, commit *Commit) error {
-
commitNodeIndex, _ := commit.repo.CommitNodeIndex()
index, err := commitNodeIndex.Get(commit.ID)
diff --git a/modules/git/lfs.go b/modules/git/lfs.go
index 79049c9824..3a809d393d 100644
--- a/modules/git/lfs.go
+++ b/modules/git/lfs.go
@@ -16,8 +16,8 @@ var once sync.Once
// CheckLFSVersion will check lfs version, if not satisfied, then disable it.
func CheckLFSVersion() {
if setting.LFS.StartServer {
- //Disable LFS client hooks if installed for the current OS user
- //Needs at least git v2.1.2
+ // Disable LFS client hooks if installed for the current OS user
+ // Needs at least git v2.1.2
err := LoadGitVersion()
if err != nil {
diff --git a/modules/git/parse_nogogit_test.go b/modules/git/parse_nogogit_test.go
index 5f58237de8..d6d6f3868c 100644
--- a/modules/git/parse_nogogit_test.go
+++ b/modules/git/parse_nogogit_test.go
@@ -14,7 +14,6 @@ import (
)
func TestParseTreeEntries(t *testing.T) {
-
testCases := []struct {
Input string
Expected []*TreeEntry
diff --git a/modules/git/repo.go b/modules/git/repo.go
index 591ef7362b..6368c6459b 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -146,7 +146,7 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
opts.Timeout = -1
}
- var envs = os.Environ()
+ envs := os.Environ()
u, err := url.Parse(from)
if err == nil && (strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https")) {
if proxy.Match(u.Host) {
@@ -154,7 +154,7 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
}
}
- var stderr = new(bytes.Buffer)
+ stderr := new(bytes.Buffer)
if err = cmd.RunWithContext(&RunContext{
Timeout: opts.Timeout,
Env: envs,
diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go
index 0bb550bb4b..d12f0b1099 100644
--- a/modules/git/repo_attribute.go
+++ b/modules/git/repo_attribute.go
@@ -87,7 +87,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[
return nil, fmt.Errorf("wrong number of fields in return from check-attr")
}
- var name2attribute2info = make(map[string]map[string]string)
+ name2attribute2info := make(map[string]map[string]string)
for i := 0; i < (len(fields) / 3); i++ {
filename := string(fields[3*i])
diff --git a/modules/git/repo_attribute_test.go b/modules/git/repo_attribute_test.go
index 92d1a78fa4..901a0aa244 100644
--- a/modules/git/repo_attribute_test.go
+++ b/modules/git/repo_attribute_test.go
@@ -45,7 +45,7 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
assert.Fail(t, "took too long to read an attribute from the list")
}
- //Write a partial attribute
+ // Write a partial attribute
_, err = wr.Write([]byte("incomplete-file"))
assert.NoError(t, err)
_, err = wr.Write([]byte("name\x00"))
@@ -133,7 +133,7 @@ func Test_lineSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
assert.Fail(t, "took too long to read an attribute from the list")
}
- //Write a partial attribute
+ // Write a partial attribute
_, err = wr.Write([]byte("incomplete-file"))
assert.NoError(t, err)
_, err = wr.Write([]byte("name: "))
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index ed04ee2f67..0423f15786 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -88,7 +88,6 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
func (repo *Repository) commitsByRange(id SHA1, page, pageSize int) ([]*Commit, error) {
stdout, err := NewCommandContext(repo.Ctx, "log", id.String(), "--skip="+strconv.Itoa((page-1)*pageSize),
"--max-count="+strconv.Itoa(pageSize), prettyLogFormat).RunInDirBytes(repo.Path)
-
if err != nil {
return nil, err
}
diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go
index 5943334843..232d6a218c 100644
--- a/modules/git/repo_commit_test.go
+++ b/modules/git/repo_commit_test.go
@@ -90,9 +90,9 @@ func TestRepository_CommitsBetweenIDs(t *testing.T) {
NewID string
ExpectedCommits int
}{
- {"fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", "78a445db1eac62fe15e624e1137965969addf344", 1}, //com1 -> com2
- {"78a445db1eac62fe15e624e1137965969addf344", "fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", 0}, //reset HEAD~, com2 -> com1
- {"78a445db1eac62fe15e624e1137965969addf344", "a78e5638b66ccfe7e1b4689d3d5684e42c97d7ca", 1}, //com2 -> com2_new
+ {"fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", "78a445db1eac62fe15e624e1137965969addf344", 1}, // com1 -> com2
+ {"78a445db1eac62fe15e624e1137965969addf344", "fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", 0}, // reset HEAD~, com2 -> com1
+ {"78a445db1eac62fe15e624e1137965969addf344", "a78e5638b66ccfe7e1b4689d3d5684e42c97d7ca", 1}, // com2 -> com2_new
}
for i, c := range cases {
commits, err := bareRepo1.CommitsBetweenIDs(c.NewID, c.OldID)
diff --git a/modules/git/repo_language_stats.go b/modules/git/repo_language_stats.go
index ac23caa0fc..daeb4b591f 100644
--- a/modules/git/repo_language_stats.go
+++ b/modules/git/repo_language_stats.go
@@ -4,5 +4,7 @@
package git
-const fileSizeLimit int64 = 16 * 1024 // 16 KiB
-const bigFileSize int64 = 1024 * 1024 // 1 MiB
+const (
+ fileSizeLimit int64 = 16 * 1024 // 16 KiB
+ bigFileSize int64 = 1024 * 1024 // 1 MiB
+)
diff --git a/modules/git/repo_object.go b/modules/git/repo_object.go
index 3921e6a1d4..1d08c6bf79 100644
--- a/modules/git/repo_object.go
+++ b/modules/git/repo_object.go
@@ -46,7 +46,6 @@ func (repo *Repository) hashObject(reader io.Reader) (string, error) {
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
err := cmd.RunInDirFullPipeline(repo.Path, stdout, stderr, reader)
-
if err != nil {
return "", err
}
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go
index 6b5dbeef48..9d1e47a497 100644
--- a/modules/git/repo_tag.go
+++ b/modules/git/repo_tag.go
@@ -174,7 +174,7 @@ func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) {
tagNames = util.PaginateSlice(tagNames, page, pageSize).([]string)
}
- var tags = make([]*Tag, 0, len(tagNames))
+ tags := make([]*Tag, 0, len(tagNames))
for _, tagName := range tagNames {
tagName = strings.TrimSpace(tagName)
if len(tagName) == 0 {
diff --git a/modules/git/submodule_test.go b/modules/git/submodule_test.go
index ff8dc579f6..653f0a6f08 100644
--- a/modules/git/submodule_test.go
+++ b/modules/git/submodule_test.go
@@ -11,7 +11,7 @@ import (
)
func TestGetRefURL(t *testing.T) {
- var kases = []struct {
+ kases := []struct {
refURL string
prefixURL string
parentPath string
diff --git a/modules/git/tag.go b/modules/git/tag.go
index 71dd866a18..3482f81e90 100644
--- a/modules/git/tag.go
+++ b/modules/git/tag.go
@@ -10,8 +10,10 @@ import (
"strings"
)
-const beginpgp = "\n-----BEGIN PGP SIGNATURE-----\n"
-const endpgp = "\n-----END PGP SIGNATURE-----"
+const (
+ beginpgp = "\n-----BEGIN PGP SIGNATURE-----\n"
+ endpgp = "\n-----END PGP SIGNATURE-----"
+)
// Tag represents a Git tag.
type Tag struct {
diff --git a/modules/git/tree_blob_gogit.go b/modules/git/tree_blob_gogit.go
index a8d619cd18..be7cb33d35 100644
--- a/modules/git/tree_blob_gogit.go
+++ b/modules/git/tree_blob_gogit.go
@@ -22,7 +22,7 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
if len(relpath) == 0 {
return &TreeEntry{
ID: t.ID,
- //Type: ObjectTree,
+ // Type: ObjectTree,
gogitTreeEntry: &object.TreeEntry{
Name: "",
Mode: filemode.Dir,
diff --git a/modules/git/tree_entry_mode.go b/modules/git/tree_entry_mode.go
index b029c6fc47..d999ccc02a 100644
--- a/modules/git/tree_entry_mode.go
+++ b/modules/git/tree_entry_mode.go
@@ -13,15 +13,15 @@ type EntryMode int
// one of these.
const (
// EntryModeBlob
- EntryModeBlob EntryMode = 0100644
+ EntryModeBlob EntryMode = 0o100644
// EntryModeExec
- EntryModeExec EntryMode = 0100755
+ EntryModeExec EntryMode = 0o100755
// EntryModeSymlink
- EntryModeSymlink EntryMode = 0120000
+ EntryModeSymlink EntryMode = 0o120000
// EntryModeCommit
- EntryModeCommit EntryMode = 0160000
+ EntryModeCommit EntryMode = 0o160000
// EntryModeTree
- EntryModeTree EntryMode = 0040000
+ EntryModeTree EntryMode = 0o040000
)
// String converts an EntryMode to a string