Skip to content

Commit 54d96c7

Browse files
mueslizeripath
authored andcommitted
Removed unnecessary conversions (#7557)
No need to convert to the same type.
1 parent 2f75766 commit 54d96c7

24 files changed

+39
-46
lines changed

integrations/version_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ func TestVersion(t *testing.T) {
2323

2424
var version structs.ServerVersion
2525
DecodeJSON(t, resp, &version)
26-
assert.Equal(t, setting.AppVer, string(version.Version))
26+
assert.Equal(t, setting.AppVer, version.Version)
2727
}

models/action.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func getIssueFromRef(repo *Repository, ref string) (*Issue, error) {
500500
return nil, nil
501501
}
502502

503-
issue, err := GetIssueByIndex(refRepo.ID, int64(issueIndex))
503+
issue, err := GetIssueByIndex(refRepo.ID, issueIndex)
504504
if err != nil {
505505
if IsErrIssueNotExist(err) {
506506
return nil, nil
@@ -565,7 +565,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
565565

566566
// issue is from another repo
567567
if len(m[1]) > 0 && len(m[2]) > 0 {
568-
refRepo, err = GetRepositoryFromMatch(string(m[1]), string(m[2]))
568+
refRepo, err = GetRepositoryFromMatch(m[1], m[2])
569569
if err != nil {
570570
continue
571571
}
@@ -602,7 +602,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
602602

603603
// issue is from another repo
604604
if len(m[1]) > 0 && len(m[2]) > 0 {
605-
refRepo, err = GetRepositoryFromMatch(string(m[1]), string(m[2]))
605+
refRepo, err = GetRepositoryFromMatch(m[1], m[2])
606606
if err != nil {
607607
continue
608608
}
@@ -631,7 +631,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
631631

632632
// issue is from another repo
633633
if len(m[1]) > 0 && len(m[2]) > 0 {
634-
refRepo, err = GetRepositoryFromMatch(string(m[1]), string(m[2]))
634+
refRepo, err = GetRepositoryFromMatch(m[1], m[2])
635635
if err != nil {
636636
continue
637637
}

models/repo_permission.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (p *Permission) ColorFormat(s fmt.State) {
113113
configBytes, err := unit.Config.ToDB()
114114
config = string(configBytes)
115115
if err != nil {
116-
config = string(err.Error())
116+
config = err.Error()
117117
}
118118
}
119119
format += "\nUnits[%d]: ID: %d RepoID: %d Type: %-v Config: %s"

modules/context/panic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Recovery() macaron.Handler {
3030
return func(ctx *Context) {
3131
defer func() {
3232
if err := recover(); err != nil {
33-
combinedErr := fmt.Errorf("%s\n%s", err, string(log.Stack(2)))
33+
combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2))
3434
ctx.ServerError("PANIC:", combinedErr)
3535
}
3636
}()

modules/git/commit_info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
2525
defer commitGraphFile.Close()
2626
}
2727

28-
c, err := commitNodeIndex.Get(plumbing.Hash(commit.ID))
28+
c, err := commitNodeIndex.Get(commit.ID)
2929
if err != nil {
3030
return nil, nil, err
3131
}

modules/git/notes.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package git
66

77
import (
88
"io/ioutil"
9-
10-
"gopkg.in/src-d/go-git.v4/plumbing"
119
)
1210

1311
// NotesRef is the git ref where Gitea will look for git-notes data.
@@ -45,7 +43,7 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
4543
}
4644
note.Message = d
4745

48-
commit, err := repo.gogitRepo.CommitObject(plumbing.Hash(notes.ID))
46+
commit, err := repo.gogitRepo.CommitObject(notes.ID)
4947
if err != nil {
5048
return err
5149
}

modules/git/parse.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"strconv"
1111

12-
"gopkg.in/src-d/go-git.v4/plumbing"
1312
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
1413
"gopkg.in/src-d/go-git.v4/plumbing/object"
1514
)
@@ -57,7 +56,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
5756
return nil, fmt.Errorf("Invalid ls-tree output: %v", err)
5857
}
5958
entry.ID = id
60-
entry.gogitTreeEntry.Hash = plumbing.Hash(id)
59+
entry.gogitTreeEntry.Hash = id
6160
pos += 41 // skip over sha and trailing space
6261

6362
end := pos + bytes.IndexByte(data[pos:], '\n')

modules/git/repo_blame.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Comm
2020
if len(res) < 40 {
2121
return nil, fmt.Errorf("invalid result of blame: %s", res)
2222
}
23-
return repo.GetCommit(string(res[:40]))
23+
return repo.GetCommit(res[:40])
2424
}

modules/git/repo_blob.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func (repo *Repository) getBlob(id SHA1) (*Blob, error) {
12-
encodedObj, err := repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, plumbing.Hash(id))
12+
encodedObj, err := repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, id)
1313
if err != nil {
1414
return nil, ErrNotExist{id.String(), ""}
1515
}

modules/git/repo_commit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ func convertPGPSignatureForTag(t *object.Tag) *CommitGPGSignature {
8686
func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
8787
var tagObject *object.Tag
8888

89-
gogitCommit, err := repo.gogitRepo.CommitObject(plumbing.Hash(id))
89+
gogitCommit, err := repo.gogitRepo.CommitObject(id)
9090
if err == plumbing.ErrObjectNotFound {
91-
tagObject, err = repo.gogitRepo.TagObject(plumbing.Hash(id))
91+
tagObject, err = repo.gogitRepo.TagObject(id)
9292
if err == nil {
9393
gogitCommit, err = repo.gogitRepo.CommitObject(tagObject.Target)
9494
}

modules/git/repo_ref.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error) {
3434
refType := string(ObjectCommit)
3535
if ref.Name().IsTag() {
3636
// tags can be of type `commit` (lightweight) or `tag` (annotated)
37-
if tagType, _ := repo.GetTagType(SHA1(ref.Hash())); err == nil {
37+
if tagType, _ := repo.GetTagType(ref.Hash()); err == nil {
3838
refType = tagType
3939
}
4040
}
4141
r := &Reference{
4242
Name: ref.Name().String(),
43-
Object: SHA1(ref.Hash()),
43+
Object: ref.Hash(),
4444
Type: refType,
4545
repo: repo,
4646
}

modules/git/repo_tree.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import (
1010
"os"
1111
"strings"
1212
"time"
13-
14-
"gopkg.in/src-d/go-git.v4/plumbing"
1513
)
1614

1715
func (repo *Repository) getTree(id SHA1) (*Tree, error) {
18-
gogitTree, err := repo.gogitRepo.TreeObject(plumbing.Hash(id))
16+
gogitTree, err := repo.gogitRepo.TreeObject(id)
1917
if err != nil {
2018
return nil, err
2119
}
@@ -41,7 +39,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) {
4139
return nil, err
4240
}
4341
resolvedID := id
44-
commitObject, err := repo.gogitRepo.CommitObject(plumbing.Hash(id))
42+
commitObject, err := repo.gogitRepo.CommitObject(id)
4543
if err == nil {
4644
id = SHA1(commitObject.TreeHash)
4745
}

modules/git/tree.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
6363
}
6464

6565
func (t *Tree) loadTreeObject() error {
66-
gogitTree, err := t.repo.gogitRepo.TreeObject(plumbing.Hash(t.ID))
66+
gogitTree, err := t.repo.gogitRepo.TreeObject(t.ID)
6767
if err != nil {
6868
return err
6969
}

modules/git/tree_blob.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path"
1010
"strings"
1111

12-
"gopkg.in/src-d/go-git.v4/plumbing"
1312
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
1413
"gopkg.in/src-d/go-git.v4/plumbing/object"
1514
)
@@ -23,7 +22,7 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
2322
gogitTreeEntry: &object.TreeEntry{
2423
Name: "",
2524
Mode: filemode.Dir,
26-
Hash: plumbing.Hash(t.ID),
25+
Hash: t.ID,
2726
},
2827
}, nil
2928
}

modules/lfs/locks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func GetListLockHandler(ctx *context.Context) {
9797
})
9898
return
9999
}
100-
lock, err := models.GetLFSLockByID(int64(v))
100+
lock, err := models.GetLFSLockByID(v)
101101
handleLockListOut(ctx, repository, lock, err)
102102
return
103103
}

modules/log/colors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ func (cv *ColoredValue) Format(s fmt.State, c rune) {
378378
return
379379
}
380380
}
381-
s.Write([]byte(*cv.colorBytes))
381+
s.Write(*cv.colorBytes)
382382
fmt.Fprintf(&protectedANSIWriter{w: s}, fmtString(s, c), *(cv.Value))
383-
s.Write([]byte(*cv.resetBytes))
383+
s.Write(*cv.resetBytes)
384384
}
385385

386386
// SetColorBytes will allow a user to set the colorBytes of a colored value

modules/log/level.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (l *Level) UnmarshalJSON(b []byte) error {
101101

102102
switch v := tmp.(type) {
103103
case string:
104-
*l = FromString(string(v))
104+
*l = FromString(v)
105105
case int:
106106
*l = FromString(Level(v).String())
107107
default:

modules/log/writer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (logger *WriterLogger) createMsg(buf *[]byte, event *Event) {
203203
(&protectedANSIWriter{
204204
w: &baw,
205205
mode: pawMode,
206-
}).Write([]byte(msg))
206+
}).Write(msg)
207207
*buf = baw
208208

209209
if event.stacktrace != "" && logger.StacktraceLevel <= event.level {

modules/markup/html.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) {
438438

439439
name += tail
440440
image := false
441-
switch ext := filepath.Ext(string(link)); ext {
441+
switch ext := filepath.Ext(link); ext {
442442
// fast path: empty string, ignore
443443
case "":
444444
break
@@ -482,7 +482,7 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) {
482482
title = props["alt"]
483483
}
484484
if title == "" {
485-
title = path.Base(string(name))
485+
title = path.Base(name)
486486
}
487487
alt := props["alt"]
488488
if alt == "" {

modules/markup/html_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestRender_Commits(t *testing.T) {
2727

2828
test := func(input, expected string) {
2929
buffer := RenderString(".md", input, setting.AppSubURL, localMetas)
30-
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
30+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
3131
}
3232

3333
var sha = "b6dd6210eaebc915fd5be5579c58cce4da2e2579"
@@ -51,7 +51,7 @@ func TestRender_CrossReferences(t *testing.T) {
5151

5252
test := func(input, expected string) {
5353
buffer := RenderString("a.md", input, setting.AppSubURL, localMetas)
54-
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
54+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
5555
}
5656

5757
test(
@@ -83,7 +83,7 @@ func TestRender_links(t *testing.T) {
8383

8484
test := func(input, expected string) {
8585
buffer := RenderString("a.md", input, setting.AppSubURL, nil)
86-
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
86+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
8787
}
8888
// Text that should be turned into URL
8989

@@ -160,7 +160,7 @@ func TestRender_email(t *testing.T) {
160160

161161
test := func(input, expected string) {
162162
buffer := RenderString("a.md", input, setting.AppSubURL, nil)
163-
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
163+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
164164
}
165165
// Text that should be turned into email link
166166

@@ -214,9 +214,9 @@ func TestRender_ShortLinks(t *testing.T) {
214214

215215
test := func(input, expected, expectedWiki string) {
216216
buffer := markdown.RenderString(input, tree, nil)
217-
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
217+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
218218
buffer = markdown.RenderWiki([]byte(input), setting.AppSubURL, localMetas)
219-
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(string(buffer)))
219+
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer))
220220
}
221221

222222
rawtree := util.URLJoin(AppSubURL, "raw", "master")

modules/markup/markdown/markdown_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestRender_StandardLinks(t *testing.T) {
3131

3232
test := func(input, expected, expectedWiki string) {
3333
buffer := RenderString(input, setting.AppSubURL, nil)
34-
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
34+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
3535
bufferWiki := RenderWiki([]byte(input), setting.AppSubURL, nil)
3636
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(bufferWiki))
3737
}
@@ -74,7 +74,7 @@ func TestRender_Images(t *testing.T) {
7474

7575
test := func(input, expected string) {
7676
buffer := RenderString(input, setting.AppSubURL, nil)
77-
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
77+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
7878
}
7979

8080
url := "../../.images/src/02/train.jpg"

modules/pull/lfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func readCatFileBatchCheck(catFileCheckReader *io.PipeReader, shasToBatchWriter
138138
if len(fields) < 3 || fields[1] != "blob" {
139139
continue
140140
}
141-
size, _ := strconv.Atoi(string(fields[2]))
141+
size, _ := strconv.Atoi(fields[2])
142142
if size > 1024 {
143143
continue
144144
}

modules/repofiles/update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up
317317
if encoding != "UTF-8" {
318318
charsetEncoding, _ := charset.Lookup(encoding)
319319
if charsetEncoding != nil {
320-
result, _, err := transform.String(charsetEncoding.NewEncoder(), string(content))
320+
result, _, err := transform.String(charsetEncoding.NewEncoder(), content)
321321
if err != nil {
322322
// Look if we can't encode back in to the original we should just stick with utf-8
323323
log.Error("Error re-encoding %s (%s) as %s - will stay as UTF-8: %v", opts.TreePath, opts.FromTreePath, encoding, err)

routers/org/setting.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"code.gitea.io/gitea/modules/context"
1515
"code.gitea.io/gitea/modules/log"
1616
"code.gitea.io/gitea/modules/setting"
17-
"code.gitea.io/gitea/modules/structs"
1817
userSetting "code.gitea.io/gitea/routers/user/setting"
1918
)
2019

@@ -31,15 +30,15 @@ const (
3130
func Settings(ctx *context.Context) {
3231
ctx.Data["Title"] = ctx.Tr("org.settings")
3332
ctx.Data["PageIsSettingsOptions"] = true
34-
ctx.Data["CurrentVisibility"] = structs.VisibleType(ctx.Org.Organization.Visibility)
33+
ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
3534
ctx.HTML(200, tplSettingsOptions)
3635
}
3736

3837
// SettingsPost response for settings change submited
3938
func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
4039
ctx.Data["Title"] = ctx.Tr("org.settings")
4140
ctx.Data["PageIsSettingsOptions"] = true
42-
ctx.Data["CurrentVisibility"] = structs.VisibleType(ctx.Org.Organization.Visibility)
41+
ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
4342

4443
if ctx.HasError() {
4544
ctx.HTML(200, tplSettingsOptions)

0 commit comments

Comments
 (0)