From 54d96c79b5b9f3d5d47aed59729ae779968fbecb Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 23 Jul 2019 20:50:39 +0200 Subject: [PATCH] Removed unnecessary conversions (#7557) No need to convert to the same type. --- integrations/version_test.go | 2 +- models/action.go | 8 ++++---- models/repo_permission.go | 2 +- modules/context/panic.go | 2 +- modules/git/commit_info.go | 2 +- modules/git/notes.go | 4 +--- modules/git/parse.go | 3 +-- modules/git/repo_blame.go | 2 +- modules/git/repo_blob.go | 2 +- modules/git/repo_commit.go | 4 ++-- modules/git/repo_ref.go | 4 ++-- modules/git/repo_tree.go | 6 ++---- modules/git/tree.go | 2 +- modules/git/tree_blob.go | 3 +-- modules/lfs/locks.go | 2 +- modules/log/colors.go | 4 ++-- modules/log/level.go | 2 +- modules/log/writer.go | 2 +- modules/markup/html.go | 4 ++-- modules/markup/html_test.go | 12 ++++++------ modules/markup/markdown/markdown_test.go | 4 ++-- modules/pull/lfs.go | 2 +- modules/repofiles/update.go | 2 +- routers/org/setting.go | 5 ++--- 24 files changed, 39 insertions(+), 46 deletions(-) diff --git a/integrations/version_test.go b/integrations/version_test.go index eaba3e085..e63ae7aee 100644 --- a/integrations/version_test.go +++ b/integrations/version_test.go @@ -23,5 +23,5 @@ func TestVersion(t *testing.T) { var version structs.ServerVersion DecodeJSON(t, resp, &version) - assert.Equal(t, setting.AppVer, string(version.Version)) + assert.Equal(t, setting.AppVer, version.Version) } diff --git a/models/action.go b/models/action.go index a092f564b..c819c286e 100644 --- a/models/action.go +++ b/models/action.go @@ -500,7 +500,7 @@ func getIssueFromRef(repo *Repository, ref string) (*Issue, error) { return nil, nil } - issue, err := GetIssueByIndex(refRepo.ID, int64(issueIndex)) + issue, err := GetIssueByIndex(refRepo.ID, issueIndex) if err != nil { if IsErrIssueNotExist(err) { return nil, nil @@ -565,7 +565,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra // issue is from another repo if len(m[1]) > 0 && len(m[2]) > 0 { - refRepo, err = GetRepositoryFromMatch(string(m[1]), string(m[2])) + refRepo, err = GetRepositoryFromMatch(m[1], m[2]) if err != nil { continue } @@ -602,7 +602,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra // issue is from another repo if len(m[1]) > 0 && len(m[2]) > 0 { - refRepo, err = GetRepositoryFromMatch(string(m[1]), string(m[2])) + refRepo, err = GetRepositoryFromMatch(m[1], m[2]) if err != nil { continue } @@ -631,7 +631,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra // issue is from another repo if len(m[1]) > 0 && len(m[2]) > 0 { - refRepo, err = GetRepositoryFromMatch(string(m[1]), string(m[2])) + refRepo, err = GetRepositoryFromMatch(m[1], m[2]) if err != nil { continue } diff --git a/models/repo_permission.go b/models/repo_permission.go index 25239f4dd..916678d16 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -113,7 +113,7 @@ func (p *Permission) ColorFormat(s fmt.State) { configBytes, err := unit.Config.ToDB() config = string(configBytes) if err != nil { - config = string(err.Error()) + config = err.Error() } } format += "\nUnits[%d]: ID: %d RepoID: %d Type: %-v Config: %s" diff --git a/modules/context/panic.go b/modules/context/panic.go index 8ed91dea6..c25133716 100644 --- a/modules/context/panic.go +++ b/modules/context/panic.go @@ -30,7 +30,7 @@ func Recovery() macaron.Handler { return func(ctx *Context) { defer func() { if err := recover(); err != nil { - combinedErr := fmt.Errorf("%s\n%s", err, string(log.Stack(2))) + combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2)) ctx.ServerError("PANIC:", combinedErr) } }() diff --git a/modules/git/commit_info.go b/modules/git/commit_info.go index 3fa80457a..d8bf88a47 100644 --- a/modules/git/commit_info.go +++ b/modules/git/commit_info.go @@ -25,7 +25,7 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom defer commitGraphFile.Close() } - c, err := commitNodeIndex.Get(plumbing.Hash(commit.ID)) + c, err := commitNodeIndex.Get(commit.ID) if err != nil { return nil, nil, err } diff --git a/modules/git/notes.go b/modules/git/notes.go index a62c55878..aea54ab20 100644 --- a/modules/git/notes.go +++ b/modules/git/notes.go @@ -6,8 +6,6 @@ package git import ( "io/ioutil" - - "gopkg.in/src-d/go-git.v4/plumbing" ) // 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 { } note.Message = d - commit, err := repo.gogitRepo.CommitObject(plumbing.Hash(notes.ID)) + commit, err := repo.gogitRepo.CommitObject(notes.ID) if err != nil { return err } diff --git a/modules/git/parse.go b/modules/git/parse.go index 22861b1d2..cbd48b918 100644 --- a/modules/git/parse.go +++ b/modules/git/parse.go @@ -9,7 +9,6 @@ import ( "fmt" "strconv" - "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/filemode" "gopkg.in/src-d/go-git.v4/plumbing/object" ) @@ -57,7 +56,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { return nil, fmt.Errorf("Invalid ls-tree output: %v", err) } entry.ID = id - entry.gogitTreeEntry.Hash = plumbing.Hash(id) + entry.gogitTreeEntry.Hash = id pos += 41 // skip over sha and trailing space end := pos + bytes.IndexByte(data[pos:], '\n') diff --git a/modules/git/repo_blame.go b/modules/git/repo_blame.go index 80ec50e47..5c023554f 100644 --- a/modules/git/repo_blame.go +++ b/modules/git/repo_blame.go @@ -20,5 +20,5 @@ func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Comm if len(res) < 40 { return nil, fmt.Errorf("invalid result of blame: %s", res) } - return repo.GetCommit(string(res[:40])) + return repo.GetCommit(res[:40]) } diff --git a/modules/git/repo_blob.go b/modules/git/repo_blob.go index db63491ce..45ca60440 100644 --- a/modules/git/repo_blob.go +++ b/modules/git/repo_blob.go @@ -9,7 +9,7 @@ import ( ) func (repo *Repository) getBlob(id SHA1) (*Blob, error) { - encodedObj, err := repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, plumbing.Hash(id)) + encodedObj, err := repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, id) if err != nil { return nil, ErrNotExist{id.String(), ""} } diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index 8429a5703..733991612 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -86,9 +86,9 @@ func convertPGPSignatureForTag(t *object.Tag) *CommitGPGSignature { func (repo *Repository) getCommit(id SHA1) (*Commit, error) { var tagObject *object.Tag - gogitCommit, err := repo.gogitRepo.CommitObject(plumbing.Hash(id)) + gogitCommit, err := repo.gogitRepo.CommitObject(id) if err == plumbing.ErrObjectNotFound { - tagObject, err = repo.gogitRepo.TagObject(plumbing.Hash(id)) + tagObject, err = repo.gogitRepo.TagObject(id) if err == nil { gogitCommit, err = repo.gogitRepo.CommitObject(tagObject.Target) } diff --git a/modules/git/repo_ref.go b/modules/git/repo_ref.go index 95a6c2ae6..9044dbead 100644 --- a/modules/git/repo_ref.go +++ b/modules/git/repo_ref.go @@ -34,13 +34,13 @@ func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error) { refType := string(ObjectCommit) if ref.Name().IsTag() { // tags can be of type `commit` (lightweight) or `tag` (annotated) - if tagType, _ := repo.GetTagType(SHA1(ref.Hash())); err == nil { + if tagType, _ := repo.GetTagType(ref.Hash()); err == nil { refType = tagType } } r := &Reference{ Name: ref.Name().String(), - Object: SHA1(ref.Hash()), + Object: ref.Hash(), Type: refType, repo: repo, } diff --git a/modules/git/repo_tree.go b/modules/git/repo_tree.go index 7d32d3685..ddc398d0b 100644 --- a/modules/git/repo_tree.go +++ b/modules/git/repo_tree.go @@ -10,12 +10,10 @@ import ( "os" "strings" "time" - - "gopkg.in/src-d/go-git.v4/plumbing" ) func (repo *Repository) getTree(id SHA1) (*Tree, error) { - gogitTree, err := repo.gogitRepo.TreeObject(plumbing.Hash(id)) + gogitTree, err := repo.gogitRepo.TreeObject(id) if err != nil { return nil, err } @@ -41,7 +39,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) { return nil, err } resolvedID := id - commitObject, err := repo.gogitRepo.CommitObject(plumbing.Hash(id)) + commitObject, err := repo.gogitRepo.CommitObject(id) if err == nil { id = SHA1(commitObject.TreeHash) } diff --git a/modules/git/tree.go b/modules/git/tree.go index 6ca893cb7..58c4d8cad 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -63,7 +63,7 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) { } func (t *Tree) loadTreeObject() error { - gogitTree, err := t.repo.gogitRepo.TreeObject(plumbing.Hash(t.ID)) + gogitTree, err := t.repo.gogitRepo.TreeObject(t.ID) if err != nil { return err } diff --git a/modules/git/tree_blob.go b/modules/git/tree_blob.go index eb8ddd094..cdbe031a2 100644 --- a/modules/git/tree_blob.go +++ b/modules/git/tree_blob.go @@ -9,7 +9,6 @@ import ( "path" "strings" - "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/filemode" "gopkg.in/src-d/go-git.v4/plumbing/object" ) @@ -23,7 +22,7 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) { gogitTreeEntry: &object.TreeEntry{ Name: "", Mode: filemode.Dir, - Hash: plumbing.Hash(t.ID), + Hash: t.ID, }, }, nil } diff --git a/modules/lfs/locks.go b/modules/lfs/locks.go index 4516ba01a..d7b242969 100644 --- a/modules/lfs/locks.go +++ b/modules/lfs/locks.go @@ -97,7 +97,7 @@ func GetListLockHandler(ctx *context.Context) { }) return } - lock, err := models.GetLFSLockByID(int64(v)) + lock, err := models.GetLFSLockByID(v) handleLockListOut(ctx, repository, lock, err) return } diff --git a/modules/log/colors.go b/modules/log/colors.go index c29741634..282d0c919 100644 --- a/modules/log/colors.go +++ b/modules/log/colors.go @@ -378,9 +378,9 @@ func (cv *ColoredValue) Format(s fmt.State, c rune) { return } } - s.Write([]byte(*cv.colorBytes)) + s.Write(*cv.colorBytes) fmt.Fprintf(&protectedANSIWriter{w: s}, fmtString(s, c), *(cv.Value)) - s.Write([]byte(*cv.resetBytes)) + s.Write(*cv.resetBytes) } // SetColorBytes will allow a user to set the colorBytes of a colored value diff --git a/modules/log/level.go b/modules/log/level.go index 6131fcb51..4b89385fe 100644 --- a/modules/log/level.go +++ b/modules/log/level.go @@ -101,7 +101,7 @@ func (l *Level) UnmarshalJSON(b []byte) error { switch v := tmp.(type) { case string: - *l = FromString(string(v)) + *l = FromString(v) case int: *l = FromString(Level(v).String()) default: diff --git a/modules/log/writer.go b/modules/log/writer.go index 2503f04d7..6f656c7ce 100644 --- a/modules/log/writer.go +++ b/modules/log/writer.go @@ -203,7 +203,7 @@ func (logger *WriterLogger) createMsg(buf *[]byte, event *Event) { (&protectedANSIWriter{ w: &baw, mode: pawMode, - }).Write([]byte(msg)) + }).Write(msg) *buf = baw if event.stacktrace != "" && logger.StacktraceLevel <= event.level { diff --git a/modules/markup/html.go b/modules/markup/html.go index 3e976929c..825a41dd1 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -438,7 +438,7 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) { name += tail image := false - switch ext := filepath.Ext(string(link)); ext { + switch ext := filepath.Ext(link); ext { // fast path: empty string, ignore case "": break @@ -482,7 +482,7 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) { title = props["alt"] } if title == "" { - title = path.Base(string(name)) + title = path.Base(name) } alt := props["alt"] if alt == "" { diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index daf953c9e..be7fb0efc 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -27,7 +27,7 @@ func TestRender_Commits(t *testing.T) { test := func(input, expected string) { buffer := RenderString(".md", input, setting.AppSubURL, localMetas) - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } var sha = "b6dd6210eaebc915fd5be5579c58cce4da2e2579" @@ -51,7 +51,7 @@ func TestRender_CrossReferences(t *testing.T) { test := func(input, expected string) { buffer := RenderString("a.md", input, setting.AppSubURL, localMetas) - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } test( @@ -83,7 +83,7 @@ func TestRender_links(t *testing.T) { test := func(input, expected string) { buffer := RenderString("a.md", input, setting.AppSubURL, nil) - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } // Text that should be turned into URL @@ -160,7 +160,7 @@ func TestRender_email(t *testing.T) { test := func(input, expected string) { buffer := RenderString("a.md", input, setting.AppSubURL, nil) - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } // Text that should be turned into email link @@ -214,9 +214,9 @@ func TestRender_ShortLinks(t *testing.T) { test := func(input, expected, expectedWiki string) { buffer := markdown.RenderString(input, tree, nil) - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) buffer = markdown.RenderWiki([]byte(input), setting.AppSubURL, localMetas) - assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer)) } rawtree := util.URLJoin(AppSubURL, "raw", "master") diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 2128639b9..92b4f03e3 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -31,7 +31,7 @@ func TestRender_StandardLinks(t *testing.T) { test := func(input, expected, expectedWiki string) { buffer := RenderString(input, setting.AppSubURL, nil) - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) bufferWiki := RenderWiki([]byte(input), setting.AppSubURL, nil) assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(bufferWiki)) } @@ -74,7 +74,7 @@ func TestRender_Images(t *testing.T) { test := func(input, expected string) { buffer := RenderString(input, setting.AppSubURL, nil) - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } url := "../../.images/src/02/train.jpg" diff --git a/modules/pull/lfs.go b/modules/pull/lfs.go index 77890667d..2706d3a20 100644 --- a/modules/pull/lfs.go +++ b/modules/pull/lfs.go @@ -138,7 +138,7 @@ func readCatFileBatchCheck(catFileCheckReader *io.PipeReader, shasToBatchWriter if len(fields) < 3 || fields[1] != "blob" { continue } - size, _ := strconv.Atoi(string(fields[2])) + size, _ := strconv.Atoi(fields[2]) if size > 1024 { continue } diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go index f011017a5..38f2f22c9 100644 --- a/modules/repofiles/update.go +++ b/modules/repofiles/update.go @@ -317,7 +317,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up if encoding != "UTF-8" { charsetEncoding, _ := charset.Lookup(encoding) if charsetEncoding != nil { - result, _, err := transform.String(charsetEncoding.NewEncoder(), string(content)) + result, _, err := transform.String(charsetEncoding.NewEncoder(), content) if err != nil { // Look if we can't encode back in to the original we should just stick with utf-8 log.Error("Error re-encoding %s (%s) as %s - will stay as UTF-8: %v", opts.TreePath, opts.FromTreePath, encoding, err) diff --git a/routers/org/setting.go b/routers/org/setting.go index b3ff01d23..1d534ec55 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -14,7 +14,6 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/structs" userSetting "code.gitea.io/gitea/routers/user/setting" ) @@ -31,7 +30,7 @@ const ( func Settings(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsOptions"] = true - ctx.Data["CurrentVisibility"] = structs.VisibleType(ctx.Org.Organization.Visibility) + ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility ctx.HTML(200, tplSettingsOptions) } @@ -39,7 +38,7 @@ func Settings(ctx *context.Context) { func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsOptions"] = true - ctx.Data["CurrentVisibility"] = structs.VisibleType(ctx.Org.Organization.Visibility) + ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility if ctx.HasError() { ctx.HTML(200, tplSettingsOptions)