Skip to content

Commit 4160bd6

Browse files
authored
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
1 parent c08c975 commit 4160bd6

File tree

10 files changed

+0
-179
lines changed

10 files changed

+0
-179
lines changed

models/issue_assignees.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,6 @@ func isUserAssignedToIssue(e Engine, issue *Issue, user *User) (isAssigned bool,
8181
return e.Get(&IssueAssignees{IssueID: issue.ID, AssigneeID: user.ID})
8282
}
8383

84-
// MakeAssigneeList concats a string with all names of the assignees. Useful for logs.
85-
func MakeAssigneeList(issue *Issue) (assigneeList string, err error) {
86-
err = issue.loadAssignees(x)
87-
if err != nil {
88-
return "", err
89-
}
90-
91-
for in, assignee := range issue.Assignees {
92-
assigneeList += assignee.Name
93-
94-
if len(issue.Assignees) > (in + 1) {
95-
assigneeList += ", "
96-
}
97-
}
98-
return
99-
}
100-
10184
// ClearAssigneeByUserID deletes all assignments of an user
10285
func clearAssigneeByUserID(sess *xorm.Session, userID int64) (err error) {
10386
_, err = sess.Delete(&IssueAssignees{AssigneeID: userID})

models/update.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@ import (
99
"strings"
1010
)
1111

12-
// PushUpdateDeleteTags updates a number of delete tags
13-
func PushUpdateDeleteTags(repo *Repository, tags []string) error {
14-
sess := x.NewSession()
15-
defer sess.Close()
16-
if err := sess.Begin(); err != nil {
17-
return fmt.Errorf("Unable to begin sess in PushUpdateDeleteTags: %v", err)
18-
}
19-
if err := pushUpdateDeleteTags(sess, repo, tags); err != nil {
20-
return err
21-
}
22-
23-
return sess.Commit()
24-
}
25-
2612
// PushUpdateDeleteTagsContext updates a number of delete tags with context
2713
func PushUpdateDeleteTagsContext(ctx DBContext, repo *Repository, tags []string) error {
2814
return pushUpdateDeleteTags(ctx.e, repo, tags)

models/user.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,21 +1315,6 @@ func UserPath(userName string) string {
13151315
return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
13161316
}
13171317

1318-
// GetUserByKeyID get user information by user's public key id
1319-
func GetUserByKeyID(keyID int64) (*User, error) {
1320-
var user User
1321-
has, err := x.Join("INNER", "public_key", "`public_key`.owner_id = `user`.id").
1322-
Where("`public_key`.id=?", keyID).
1323-
Get(&user)
1324-
if err != nil {
1325-
return nil, err
1326-
}
1327-
if !has {
1328-
return nil, ErrUserNotExist{0, "", keyID}
1329-
}
1330-
return &user, nil
1331-
}
1332-
13331318
func getUserByID(e Engine, id int64) (*User, error) {
13341319
u := new(User)
13351320
has, err := e.ID(id).Get(u)

modules/base/tool.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ package base
66

77
import (
88
"crypto/md5"
9-
"crypto/rand"
109
"crypto/sha1"
1110
"crypto/sha256"
1211
"encoding/base64"
1312
"encoding/hex"
1413
"fmt"
15-
"io"
1614
"net/http"
1715
"net/url"
1816
"os"
@@ -75,18 +73,6 @@ func BasicAuthEncode(username, password string) string {
7573
return base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
7674
}
7775

78-
// GetRandomBytesAsBase64 generates a random base64 string from n bytes
79-
func GetRandomBytesAsBase64(n int) string {
80-
bytes := make([]byte, 32)
81-
_, err := io.ReadFull(rand.Reader, bytes)
82-
83-
if err != nil {
84-
log.Fatal("Error reading random bytes: %v", err)
85-
}
86-
87-
return base64.RawURLEncoding.EncodeToString(bytes)
88-
}
89-
9076
// VerifyTimeLimitCode verify time limit code
9177
func VerifyTimeLimitCode(data string, minutes int, code string) bool {
9278
if len(code) <= 18 {

modules/structs/user_app.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66
package structs
77

88
import (
9-
"encoding/base64"
109
"time"
1110
)
1211

13-
// BasicAuthEncode generate base64 of basic auth head
14-
func BasicAuthEncode(user, pass string) string {
15-
return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))
16-
}
17-
1812
// AccessToken represents an API access token.
1913
// swagger:response AccessToken
2014
type AccessToken struct {

modules/structs/utils.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

modules/templates/helper.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -437,31 +437,6 @@ func Sha1(str string) string {
437437
return base.EncodeSha1(str)
438438
}
439439

440-
// ReplaceLeft replaces all prefixes 'oldS' in 's' with 'newS'.
441-
func ReplaceLeft(s, oldS, newS string) string {
442-
oldLen, newLen, i, n := len(oldS), len(newS), 0, 0
443-
for ; i < len(s) && strings.HasPrefix(s[i:], oldS); n++ {
444-
i += oldLen
445-
}
446-
447-
// simple optimization
448-
if n == 0 {
449-
return s
450-
}
451-
452-
// allocating space for the new string
453-
curLen := n*newLen + len(s[i:])
454-
replacement := make([]byte, curLen)
455-
456-
j := 0
457-
for ; j < n*newLen; j += newLen {
458-
copy(replacement[j:j+newLen], newS)
459-
}
460-
461-
copy(replacement[j:], s[i:])
462-
return string(replacement)
463-
}
464-
465440
// RenderCommitMessage renders commit message with XSS-safe and special links.
466441
func RenderCommitMessage(msg, urlPrefix string, metas map[string]string) template.HTML {
467442
return RenderCommitMessageLink(msg, urlPrefix, "", metas)

routers/api/v1/utils/utils.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ import (
1313
"code.gitea.io/gitea/modules/convert"
1414
)
1515

16-
// UserID user ID of authenticated user, or 0 if not authenticated
17-
func UserID(ctx *context.APIContext) int64 {
18-
if ctx.User == nil {
19-
return 0
20-
}
21-
return ctx.User.ID
22-
}
23-
2416
// GetQueryBeforeSince return parsed time (unix format) from URL query's before and since
2517
func GetQueryBeforeSince(ctx *context.APIContext) (before, since int64, err error) {
2618
qCreatedBefore := strings.Trim(ctx.Query("before"), " ")

routers/private/internal.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package private
88
import (
99
"strings"
1010

11-
"code.gitea.io/gitea/models"
1211
"code.gitea.io/gitea/modules/log"
1312
"code.gitea.io/gitea/modules/private"
1413
"code.gitea.io/gitea/modules/setting"
@@ -27,55 +26,6 @@ func CheckInternalToken(ctx *macaron.Context) {
2726
}
2827
}
2928

30-
//GetRepositoryByOwnerAndName chainload to models.GetRepositoryByOwnerAndName
31-
func GetRepositoryByOwnerAndName(ctx *macaron.Context) {
32-
//TODO use repo.Get(ctx *context.APIContext) ?
33-
ownerName := ctx.Params(":owner")
34-
repoName := ctx.Params(":repo")
35-
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
36-
if err != nil {
37-
ctx.JSON(500, map[string]interface{}{
38-
"err": err.Error(),
39-
})
40-
return
41-
}
42-
ctx.JSON(200, repo)
43-
}
44-
45-
//CheckUnitUser chainload to models.CheckUnitUser
46-
func CheckUnitUser(ctx *macaron.Context) {
47-
repoID := ctx.ParamsInt64(":repoid")
48-
userID := ctx.ParamsInt64(":userid")
49-
repo, err := models.GetRepositoryByID(repoID)
50-
if err != nil {
51-
ctx.JSON(500, map[string]interface{}{
52-
"err": err.Error(),
53-
})
54-
return
55-
}
56-
57-
var user *models.User
58-
if userID > 0 {
59-
user, err = models.GetUserByID(userID)
60-
if err != nil {
61-
ctx.JSON(500, map[string]interface{}{
62-
"err": err.Error(),
63-
})
64-
return
65-
}
66-
}
67-
68-
perm, err := models.GetUserRepoPermission(repo, user)
69-
if err != nil {
70-
ctx.JSON(500, map[string]interface{}{
71-
"err": err.Error(),
72-
})
73-
return
74-
}
75-
76-
ctx.JSON(200, perm.UnitAccessMode(models.UnitType(ctx.QueryInt("unitType"))))
77-
}
78-
7929
// RegisterRoutes registers all internal APIs routes to web application.
8030
// These APIs will be invoked by internal commands for example `gitea serv` and etc.
8131
func RegisterRoutes(m *macaron.Macaron) {

services/pull/patch.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ import (
1919
"code.gitea.io/gitea/modules/log"
2020
)
2121

22-
// DownloadDiff will write the patch for the pr to the writer
23-
func DownloadDiff(pr *models.PullRequest, w io.Writer, patch bool) error {
24-
return DownloadDiffOrPatch(pr, w, false)
25-
}
26-
27-
// DownloadPatch will write the patch for the pr to the writer
28-
func DownloadPatch(pr *models.PullRequest, w io.Writer, patch bool) error {
29-
return DownloadDiffOrPatch(pr, w, true)
30-
}
31-
3222
// DownloadDiffOrPatch will write the patch for the pr to the writer
3323
func DownloadDiffOrPatch(pr *models.PullRequest, w io.Writer, patch bool) error {
3424
// Clone base repo.

0 commit comments

Comments
 (0)