Skip to content

Remove Unused Functions #10516

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

Merged
merged 21 commits into from
Mar 1, 2020
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
17 changes: 0 additions & 17 deletions models/issue_assignees.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
14 changes: 0 additions & 14 deletions models/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions modules/structs/user_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 0 additions & 20 deletions modules/structs/utils.go

This file was deleted.

25 changes: 0 additions & 25 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions routers/api/v1/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"), " ")
Expand Down
50 changes: 0 additions & 50 deletions routers/private/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
10 changes: 0 additions & 10 deletions services/pull/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down