Removed unnecessary conversions (#7557)

No need to convert to the same type.
pull/7554/head^2
Christian Muehlhaeuser 5 years ago committed by zeripath
parent 2f75766532
commit 54d96c79b5
  1. 2
      integrations/version_test.go
  2. 8
      models/action.go
  3. 2
      models/repo_permission.go
  4. 2
      modules/context/panic.go
  5. 2
      modules/git/commit_info.go
  6. 4
      modules/git/notes.go
  7. 3
      modules/git/parse.go
  8. 2
      modules/git/repo_blame.go
  9. 2
      modules/git/repo_blob.go
  10. 4
      modules/git/repo_commit.go
  11. 4
      modules/git/repo_ref.go
  12. 6
      modules/git/repo_tree.go
  13. 2
      modules/git/tree.go
  14. 3
      modules/git/tree_blob.go
  15. 2
      modules/lfs/locks.go
  16. 4
      modules/log/colors.go
  17. 2
      modules/log/level.go
  18. 2
      modules/log/writer.go
  19. 4
      modules/markup/html.go
  20. 12
      modules/markup/html_test.go
  21. 4
      modules/markup/markdown/markdown_test.go
  22. 2
      modules/pull/lfs.go
  23. 2
      modules/repofiles/update.go
  24. 5
      routers/org/setting.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)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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