Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unnecessary conversions #7557

Merged
merged 3 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integrations/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion models/repo_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion modules/context/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion modules/git/commit_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions modules/git/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions modules/git/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion modules/git/repo_blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
2 changes: 1 addition & 1 deletion modules/git/repo_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(), ""}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/git/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions modules/git/repo_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
6 changes: 2 additions & 4 deletions modules/git/repo_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/git/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions modules/git/tree_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion modules/lfs/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions modules/log/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/log/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion modules/log/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 == "" {
Expand Down
12 changes: 6 additions & 6 deletions modules/markup/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion modules/pull/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion modules/repofiles/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions routers/org/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -31,15 +30,15 @@ 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)
}

// SettingsPost response for settings change submited
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)
Expand Down