Browse Source

Removed unnecessary conversions (#7557)

No need to convert to the same type.
for-closed-social
Christian Muehlhaeuser 5 years ago
committed by zeripath
parent
commit
54d96c79b5
24 changed files with 39 additions and 46 deletions
  1. +1
    -1
      integrations/version_test.go
  2. +4
    -4
      models/action.go
  3. +1
    -1
      models/repo_permission.go
  4. +1
    -1
      modules/context/panic.go
  5. +1
    -1
      modules/git/commit_info.go
  6. +1
    -3
      modules/git/notes.go
  7. +1
    -2
      modules/git/parse.go
  8. +1
    -1
      modules/git/repo_blame.go
  9. +1
    -1
      modules/git/repo_blob.go
  10. +2
    -2
      modules/git/repo_commit.go
  11. +2
    -2
      modules/git/repo_ref.go
  12. +2
    -4
      modules/git/repo_tree.go
  13. +1
    -1
      modules/git/tree.go
  14. +1
    -2
      modules/git/tree_blob.go
  15. +1
    -1
      modules/lfs/locks.go
  16. +2
    -2
      modules/log/colors.go
  17. +1
    -1
      modules/log/level.go
  18. +1
    -1
      modules/log/writer.go
  19. +2
    -2
      modules/markup/html.go
  20. +6
    -6
      modules/markup/html_test.go
  21. +2
    -2
      modules/markup/markdown/markdown_test.go
  22. +1
    -1
      modules/pull/lfs.go
  23. +1
    -1
      modules/repofiles/update.go
  24. +2
    -3
      routers/org/setting.go

+ 1
- 1
integrations/version_test.go View File

@ -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)
}

+ 4
- 4
models/action.go View File

@ -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
}

+ 1
- 1
models/repo_permission.go View File

@ -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"

+ 1
- 1
modules/context/panic.go View File

@ -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)
}
}()

+ 1
- 1
modules/git/commit_info.go View File

@ -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
}

+ 1
- 3
modules/git/notes.go View File

@ -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
}

+ 1
- 2
modules/git/parse.go View File

@ -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')

+ 1
- 1
modules/git/repo_blame.go View File

@ -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])
}

+ 1
- 1
modules/git/repo_blob.go View File

@ -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(), ""}
}

+ 2
- 2
modules/git/repo_commit.go View File

@ -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)
}

+ 2
- 2
modules/git/repo_ref.go View File

@ -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,
}

+ 2
- 4
modules/git/repo_tree.go View File

@ -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)
}

+ 1
- 1
modules/git/tree.go View File

@ -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
}

+ 1
- 2
modules/git/tree_blob.go View File

@ -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
}

+ 1
- 1
modules/lfs/locks.go View File

@ -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
}

+ 2
- 2
modules/log/colors.go View File

@ -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

+ 1
- 1
modules/log/level.go View File

@ -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:

+ 1
- 1
modules/log/writer.go View File

@ -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 {

+ 2
- 2
modules/markup/html.go View File

@ -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 == "" {

+ 6
- 6
modules/markup/html_test.go View File

@ -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")

+ 2
- 2
modules/markup/markdown/markdown_test.go View File

@ -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"

+ 1
- 1
modules/pull/lfs.go View File

@ -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
}

+ 1
- 1
modules/repofiles/update.go View File

@ -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)

+ 2
- 3
routers/org/setting.go View File

@ -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)

Loading…
Cancel
Save