Remove Unused Functions (#10516)

* remove ReplaceLeft

* remove GetRepositoryByOwnerAndName chainload to models.GetRepositoryByOwnerAndName

* remove CheckUnitUser chainload to models.CheckUnitUser

* remove MakeAssigneeList

* remove DownloadDiff & DownloadPatch -> DownloadDiffOrPatch

* remove GetRandomBytesAsBase64

* remove PushUpdateDeleteTags

* remove GetUserByKeyID
(you still can resolve user by "k, err := GetPublicKeyByID; userID := k.OwnerID")

* remove BasicAuthEncode from struct package -> same function in modules/base/tools !

* remove UserID from api.utils

* remove unused func from structs package
pull/10560/head^2
6543 5 years ago committed by GitHub
parent c08c975d36
commit 4160bd6ef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      models/issue_assignees.go
  2. 14
      models/update.go
  3. 15
      models/user.go
  4. 14
      modules/base/tool.go
  5. 6
      modules/structs/user_app.go
  6. 20
      modules/structs/utils.go
  7. 25
      modules/templates/helper.go
  8. 8
      routers/api/v1/utils/utils.go
  9. 50
      routers/private/internal.go
  10. 10
      services/pull/patch.go

@ -81,23 +81,6 @@ func isUserAssignedToIssue(e Engine, issue *Issue, user *User) (isAssigned bool,
return e.Get(&IssueAssignees{IssueID: issue.ID, AssigneeID: user.ID})
}
// MakeAssigneeList concats a string with all names of the assignees. Useful for logs.
func MakeAssigneeList(issue *Issue) (assigneeList string, err error) {
err = issue.loadAssignees(x)
if err != nil {
return "", err
}
for in, assignee := range issue.Assignees {
assigneeList += assignee.Name
if len(issue.Assignees) > (in + 1) {
assigneeList += ", "
}
}
return
}
// ClearAssigneeByUserID deletes all assignments of an user
func clearAssigneeByUserID(sess *xorm.Session, userID int64) (err error) {
_, err = sess.Delete(&IssueAssignees{AssigneeID: userID})

@ -9,20 +9,6 @@ import (
"strings"
)
// PushUpdateDeleteTags updates a number of delete tags
func PushUpdateDeleteTags(repo *Repository, tags []string) error {
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return fmt.Errorf("Unable to begin sess in PushUpdateDeleteTags: %v", err)
}
if err := pushUpdateDeleteTags(sess, repo, tags); err != nil {
return err
}
return sess.Commit()
}
// PushUpdateDeleteTagsContext updates a number of delete tags with context
func PushUpdateDeleteTagsContext(ctx DBContext, repo *Repository, tags []string) error {
return pushUpdateDeleteTags(ctx.e, repo, tags)

@ -1315,21 +1315,6 @@ func UserPath(userName string) string {
return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
}
// GetUserByKeyID get user information by user's public key id
func GetUserByKeyID(keyID int64) (*User, error) {
var user User
has, err := x.Join("INNER", "public_key", "`public_key`.owner_id = `user`.id").
Where("`public_key`.id=?", keyID).
Get(&user)
if err != nil {
return nil, err
}
if !has {
return nil, ErrUserNotExist{0, "", keyID}
}
return &user, nil
}
func getUserByID(e Engine, id int64) (*User, error) {
u := new(User)
has, err := e.ID(id).Get(u)

@ -6,13 +6,11 @@ package base
import (
"crypto/md5"
"crypto/rand"
"crypto/sha1"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
"net/http"
"net/url"
"os"
@ -75,18 +73,6 @@ func BasicAuthEncode(username, password string) string {
return base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
}
// GetRandomBytesAsBase64 generates a random base64 string from n bytes
func GetRandomBytesAsBase64(n int) string {
bytes := make([]byte, 32)
_, err := io.ReadFull(rand.Reader, bytes)
if err != nil {
log.Fatal("Error reading random bytes: %v", err)
}
return base64.RawURLEncoding.EncodeToString(bytes)
}
// VerifyTimeLimitCode verify time limit code
func VerifyTimeLimitCode(data string, minutes int, code string) bool {
if len(code) <= 18 {

@ -6,15 +6,9 @@
package structs
import (
"encoding/base64"
"time"
)
// BasicAuthEncode generate base64 of basic auth head
func BasicAuthEncode(user, pass string) string {
return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))
}
// AccessToken represents an API access token.
// swagger:response AccessToken
type AccessToken struct {

@ -1,20 +0,0 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package structs
// Bool return address of bool value
func Bool(v bool) *bool {
return &v
}
// String return address of string value
func String(v string) *string {
return &v
}
// Int64 return address of int64 value
func Int64(v int64) *int64 {
return &v
}

@ -437,31 +437,6 @@ func Sha1(str string) string {
return base.EncodeSha1(str)
}
// ReplaceLeft replaces all prefixes 'oldS' in 's' with 'newS'.
func ReplaceLeft(s, oldS, newS string) string {
oldLen, newLen, i, n := len(oldS), len(newS), 0, 0
for ; i < len(s) && strings.HasPrefix(s[i:], oldS); n++ {
i += oldLen
}
// simple optimization
if n == 0 {
return s
}
// allocating space for the new string
curLen := n*newLen + len(s[i:])
replacement := make([]byte, curLen)
j := 0
for ; j < n*newLen; j += newLen {
copy(replacement[j:j+newLen], newS)
}
copy(replacement[j:], s[i:])
return string(replacement)
}
// RenderCommitMessage renders commit message with XSS-safe and special links.
func RenderCommitMessage(msg, urlPrefix string, metas map[string]string) template.HTML {
return RenderCommitMessageLink(msg, urlPrefix, "", metas)

@ -13,14 +13,6 @@ import (
"code.gitea.io/gitea/modules/convert"
)
// UserID user ID of authenticated user, or 0 if not authenticated
func UserID(ctx *context.APIContext) int64 {
if ctx.User == nil {
return 0
}
return ctx.User.ID
}
// GetQueryBeforeSince return parsed time (unix format) from URL query's before and since
func GetQueryBeforeSince(ctx *context.APIContext) (before, since int64, err error) {
qCreatedBefore := strings.Trim(ctx.Query("before"), " ")

@ -8,7 +8,6 @@ package private
import (
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/setting"
@ -27,55 +26,6 @@ func CheckInternalToken(ctx *macaron.Context) {
}
}
//GetRepositoryByOwnerAndName chainload to models.GetRepositoryByOwnerAndName
func GetRepositoryByOwnerAndName(ctx *macaron.Context) {
//TODO use repo.Get(ctx *context.APIContext) ?
ownerName := ctx.Params(":owner")
repoName := ctx.Params(":repo")
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
if err != nil {
ctx.JSON(500, map[string]interface{}{
"err": err.Error(),
})
return
}
ctx.JSON(200, repo)
}
//CheckUnitUser chainload to models.CheckUnitUser
func CheckUnitUser(ctx *macaron.Context) {
repoID := ctx.ParamsInt64(":repoid")
userID := ctx.ParamsInt64(":userid")
repo, err := models.GetRepositoryByID(repoID)
if err != nil {
ctx.JSON(500, map[string]interface{}{
"err": err.Error(),
})
return
}
var user *models.User
if userID > 0 {
user, err = models.GetUserByID(userID)
if err != nil {
ctx.JSON(500, map[string]interface{}{
"err": err.Error(),
})
return
}
}
perm, err := models.GetUserRepoPermission(repo, user)
if err != nil {
ctx.JSON(500, map[string]interface{}{
"err": err.Error(),
})
return
}
ctx.JSON(200, perm.UnitAccessMode(models.UnitType(ctx.QueryInt("unitType"))))
}
// RegisterRoutes registers all internal APIs routes to web application.
// These APIs will be invoked by internal commands for example `gitea serv` and etc.
func RegisterRoutes(m *macaron.Macaron) {

@ -19,16 +19,6 @@ import (
"code.gitea.io/gitea/modules/log"
)
// DownloadDiff will write the patch for the pr to the writer
func DownloadDiff(pr *models.PullRequest, w io.Writer, patch bool) error {
return DownloadDiffOrPatch(pr, w, false)
}
// DownloadPatch will write the patch for the pr to the writer
func DownloadPatch(pr *models.PullRequest, w io.Writer, patch bool) error {
return DownloadDiffOrPatch(pr, w, true)
}
// DownloadDiffOrPatch will write the patch for the pr to the writer
func DownloadDiffOrPatch(pr *models.PullRequest, w io.Writer, patch bool) error {
// Clone base repo.

Loading…
Cancel
Save