loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[DEADCODE] Add deadcode linter

- Add the experimental
[deacode](https://pkg.go.dev/golang.org/x/tools/internal/cmd/deadcode)
linter to Forgejo.
- To deal with false positives that can happen due to build tags or with code
that's currently only referenced by test code, the output of the tool is
compared against a known-good output.
- This commit doesn't make any attempt to remove any deadcode.

(cherry picked from commit ac462279e9361070326d512fc209b6f148f27865)
(cherry picked from commit b5ea6e85acecb8c02d18d51ec489bb1d329a33ce)
(cherry picked from commit 5915f3643c1939ab09dcac8f9fcb74bd4231a16d)

[CLEANUP] Remove deadcode

- This is deadcode since https://codeberg.org/forgejo/forgejo/pulls/1802
removed the usage of it.

(cherry picked from commit d840b9923e1a7aad7306c6b4d02df771ed0f40f4)
(cherry picked from commit 9442bab6266807141a14a647d3bc383233fc56e9)
(cherry picked from commit 0de9d18863c6af44941c7021548cdb07173ba3c0)
(cherry picked from commit 26abf783746ef29e66eea966160e2f9c139add26)
(cherry picked from commit 05d3a143c3785f3cc5e7f561aa2ad2ba556b55cc)
(cherry picked from commit 4b3d38d5e15b0fd02839d5687b634e7999e12666)
(cherry picked from commit a726e7198613b330a58c8c6dfc8866c360fbe555)
(cherry picked from commit cb62ae5b9885bcd5c2b6cb60f0e9cce6a991cc3c)
(cherry picked from commit 8195ba06d52fc1a05e9907149bb441b66887870e)
(cherry picked from commit 4570fb591aac0359a36800c8cadcd71613bdc7df)
(cherry picked from commit 1f4d33de2b68c776a305fe38fe6be5ae510ce983)

authored by

Gusted and committed by
Earl Warren
089f51a6 c7a389f2

+376 -73
+366
.deadcode-out
··· 1 + package "code.gitea.io/gitea/cmd" 2 + func NoMainListener 3 + 4 + package "code.gitea.io/gitea/cmd/forgejo" 5 + func ContextSetNoInit 6 + func ContextSetNoExit 7 + func ContextSetStderr 8 + func ContextGetStderr 9 + func ContextSetStdout 10 + func ContextSetStdin 11 + 12 + package "code.gitea.io/gitea/models" 13 + func IsErrUpdateTaskNotExist 14 + func (ErrUpdateTaskNotExist).Error 15 + func (ErrUpdateTaskNotExist).Unwrap 16 + func IsErrSHANotFound 17 + func GetYamlFixturesAccess 18 + 19 + package "code.gitea.io/gitea/models/actions" 20 + func ListUploadedArtifactsByRunID 21 + func CountRunJobs 22 + func (ScheduleList).GetUserIDs 23 + func (ScheduleList).GetRepoIDs 24 + func (ScheduleList).LoadTriggerUser 25 + func (ScheduleList).LoadRepos 26 + func FindSchedules 27 + func CountSpecs 28 + func GetVariableByID 29 + 30 + package "code.gitea.io/gitea/models/asymkey" 31 + func HasDeployKey 32 + 33 + package "code.gitea.io/gitea/models/auth" 34 + func DeleteAuthTokenByID 35 + func GetSourceByName 36 + func GetWebAuthnCredentialByID 37 + func WebAuthnCredentials 38 + 39 + package "code.gitea.io/gitea/models/db" 40 + func TruncateBeans 41 + func InTransaction 42 + func DumpTables 43 + func Count 44 + func FindAndCount 45 + 46 + package "code.gitea.io/gitea/models/dbfs" 47 + func (*file).renameTo 48 + func Create 49 + func Rename 50 + 51 + package "code.gitea.io/gitea/models/forgejo/semver" 52 + func GetVersion 53 + func SetVersionString 54 + func SetVersion 55 + 56 + package "code.gitea.io/gitea/models/forgejo_migrations" 57 + func GetCurrentDBVersion 58 + func EnsureUpToDate 59 + 60 + package "code.gitea.io/gitea/models/git" 61 + func RemoveDeletedBranchByID 62 + 63 + package "code.gitea.io/gitea/models/issues" 64 + func IsErrUnknownDependencyType 65 + func (ErrNewIssueInsert).Error 66 + func IsErrIssueWasClosed 67 + func GetIssueWithAttrsByID 68 + func GetRepoIDsForIssuesOptions 69 + func GetLabelIDsInOrgByNames 70 + func ChangeMilestoneStatus 71 + func GetMilestonesByRepoIDs 72 + func CountMilestonesByRepoCond 73 + func GetMilestonesStatsByRepoCond 74 + func IsErrErrPullRequestHeadRepoMissing 75 + func (ErrPullRequestHeadRepoMissing).Error 76 + func GetPullRequestsByHeadBranch 77 + func (ErrIssueStopwatchAlreadyExist).Error 78 + func (ErrIssueStopwatchAlreadyExist).Unwrap 79 + 80 + package "code.gitea.io/gitea/models/migrations/base" 81 + func removeAllWithRetry 82 + func newXORMEngine 83 + func deleteDB 84 + func PrepareTestEnv 85 + func MainTest 86 + 87 + package "code.gitea.io/gitea/models/organization" 88 + func UpdateTeamUnits 89 + func (SearchMembersOptions).ToConds 90 + func UsersInTeamsCount 91 + 92 + package "code.gitea.io/gitea/models/packages/alpine" 93 + func GetBranches 94 + func GetRepositories 95 + func GetArchitectures 96 + 97 + package "code.gitea.io/gitea/models/perm/access" 98 + func GetRepoWriters 99 + 100 + package "code.gitea.io/gitea/models/project" 101 + func UpdateBoardSorting 102 + func ChangeProjectStatus 103 + 104 + package "code.gitea.io/gitea/models/repo" 105 + func DeleteAttachmentsByIssue 106 + func (*releaseSorter).Len 107 + func (*releaseSorter).Less 108 + func (*releaseSorter).Swap 109 + func SortReleases 110 + func (SearchOrderBy).String 111 + func IsErrTopicNotExist 112 + func (ErrTopicNotExist).Error 113 + func (ErrTopicNotExist).Unwrap 114 + func GetTopicByName 115 + func WatchRepoMode 116 + 117 + package "code.gitea.io/gitea/models/system" 118 + func DeleteNotice 119 + 120 + package "code.gitea.io/gitea/models/unittest" 121 + func CheckConsistencyFor 122 + func checkForConsistency 123 + func GetXORMEngine 124 + func OverrideFixtures 125 + func InitFixtures 126 + func LoadFixtures 127 + func Copy 128 + func CopyDir 129 + func FixturesDir 130 + func fatalTestError 131 + func InitSettings 132 + func MainTest 133 + func CreateTestEngine 134 + func PrepareTestDatabase 135 + func PrepareTestEnv 136 + func Cond 137 + func OrderBy 138 + func LoadBeanIfExists 139 + func BeanExists 140 + func AssertExistsAndLoadBean 141 + func GetCount 142 + func AssertNotExistsBean 143 + func AssertExistsIf 144 + func AssertSuccessfulInsert 145 + func AssertCount 146 + func AssertInt64InRange 147 + 148 + package "code.gitea.io/gitea/models/user" 149 + func IsErrPrimaryEmailCannotDelete 150 + func (ErrUserInactive).Error 151 + func (ErrUserInactive).Unwrap 152 + func IsErrExternalLoginUserAlreadyExist 153 + func IsErrExternalLoginUserNotExist 154 + func IsErrUserSettingIsNotExist 155 + func GetUserAllSettings 156 + func DeleteUserSetting 157 + func GetUserEmailsByNames 158 + 159 + package "code.gitea.io/gitea/modules/activitypub" 160 + func CurrentTime 161 + func containsRequiredHTTPHeaders 162 + func NewClient 163 + func (*Client).NewRequest 164 + func (*Client).Post 165 + func GetPrivateKey 166 + 167 + package "code.gitea.io/gitea/modules/assetfs" 168 + func Bindata 169 + 170 + package "code.gitea.io/gitea/modules/auth/password/hash" 171 + func (*DummyHasher).HashWithSaltBytes 172 + func NewDummyHasher 173 + 174 + package "code.gitea.io/gitea/modules/auth/password/pwn" 175 + func WithHTTP 176 + 177 + package "code.gitea.io/gitea/modules/base" 178 + func BasicAuthEncode 179 + func IsLetter 180 + func SetupGiteaRoot 181 + 182 + package "code.gitea.io/gitea/modules/cache" 183 + func GetInt 184 + func WithNoCacheContext 185 + func RemoveContextData 186 + 187 + package "code.gitea.io/gitea/modules/charset" 188 + func (*BreakWriter).Write 189 + func ToUTF8 190 + func EscapeControlString 191 + 192 + package "code.gitea.io/gitea/modules/context" 193 + func GetPrivateContext 194 + 195 + package "code.gitea.io/gitea/modules/emoji" 196 + func ReplaceCodes 197 + 198 + package "code.gitea.io/gitea/modules/eventsource" 199 + func (*Event).String 200 + 201 + package "code.gitea.io/gitea/modules/git" 202 + func AllowLFSFiltersArgs 203 + func AddChanges 204 + func AddChangesWithArgs 205 + func CommitChanges 206 + func CommitChangesWithArgs 207 + func IsErrExecTimeout 208 + func (ErrExecTimeout).Error 209 + func (ErrUnsupportedVersion).Error 210 + func SetUpdateHook 211 + func openRepositoryWithDefaultContext 212 + func GetBranchCommitID 213 + func IsTagExist 214 + func ToEntryMode 215 + func (*LimitedReaderCloser).Read 216 + func (*LimitedReaderCloser).Close 217 + 218 + package "code.gitea.io/gitea/modules/gitgraph" 219 + func (*Parser).Reset 220 + 221 + package "code.gitea.io/gitea/modules/graceful" 222 + func (*Manager).TerminateContext 223 + func (*Manager).IsTerminate 224 + func (*Manager).Err 225 + func (*Manager).Value 226 + func (*Manager).Deadline 227 + 228 + package "code.gitea.io/gitea/modules/hcaptcha" 229 + func WithHTTP 230 + 231 + package "code.gitea.io/gitea/modules/json" 232 + func (StdJSON).Marshal 233 + func (StdJSON).Unmarshal 234 + func (StdJSON).NewEncoder 235 + func (StdJSON).NewDecoder 236 + func (StdJSON).Indent 237 + 238 + package "code.gitea.io/gitea/modules/markup" 239 + func GetRendererByType 240 + func RenderString 241 + func IsMarkupFile 242 + 243 + package "code.gitea.io/gitea/modules/markup/console" 244 + func Render 245 + func RenderString 246 + 247 + package "code.gitea.io/gitea/modules/markup/markdown" 248 + func IsDetails 249 + func IsSummary 250 + func IsTaskCheckBoxListItem 251 + func IsIcon 252 + func IsColorPreview 253 + func RenderRawString 254 + 255 + package "code.gitea.io/gitea/modules/markup/markdown/math" 256 + func WithInlineDollarParser 257 + func WithBlockDollarParser 258 + 259 + package "code.gitea.io/gitea/modules/markup/mdstripper" 260 + func StripMarkdown 261 + 262 + package "code.gitea.io/gitea/modules/markup/orgmode" 263 + func RenderString 264 + 265 + package "code.gitea.io/gitea/modules/private" 266 + func ActionsRunnerRegister 267 + 268 + package "code.gitea.io/gitea/modules/process" 269 + func (*Manager).ExecTimeout 270 + 271 + package "code.gitea.io/gitea/modules/queue" 272 + func newBaseChannelSimple 273 + func newBaseChannelUnique 274 + func newBaseRedisSimple 275 + func newBaseRedisUnique 276 + func newWorkerPoolQueueForTest 277 + 278 + package "code.gitea.io/gitea/modules/queue/lqinternal" 279 + func QueueItemIDBytes 280 + func QueueItemKeyBytes 281 + func ListLevelQueueKeys 282 + 283 + package "code.gitea.io/gitea/modules/setting" 284 + func NewConfigProviderFromData 285 + func (*GitConfigType).GetOption 286 + func InitLoggersForTest 287 + 288 + package "code.gitea.io/gitea/modules/storage" 289 + func (ErrInvalidConfiguration).Error 290 + func IsErrInvalidConfiguration 291 + 292 + package "code.gitea.io/gitea/modules/structs" 293 + func ParseCreateHook 294 + func ParsePushHook 295 + 296 + package "code.gitea.io/gitea/modules/sync" 297 + func (*StatusTable).Start 298 + func (*StatusTable).IsRunning 299 + 300 + package "code.gitea.io/gitea/modules/testlogger" 301 + func (*testLoggerWriterCloser).pushT 302 + func (*testLoggerWriterCloser).Write 303 + func (*testLoggerWriterCloser).popT 304 + func (*testLoggerWriterCloser).Close 305 + func (*testLoggerWriterCloser).Reset 306 + func PrintCurrentTest 307 + func Printf 308 + func NewTestLoggerWriter 309 + 310 + package "code.gitea.io/gitea/modules/timeutil" 311 + func GetExecutableModTime 312 + func Set 313 + func Unset 314 + 315 + package "code.gitea.io/gitea/modules/translation" 316 + func (MockLocale).Language 317 + func (MockLocale).Tr 318 + func (MockLocale).TrN 319 + func (MockLocale).PrettyNumber 320 + 321 + package "code.gitea.io/gitea/modules/util/filebuffer" 322 + func CreateFromReader 323 + 324 + package "code.gitea.io/gitea/modules/web" 325 + func RouteMock 326 + func RouteMockReset 327 + 328 + package "code.gitea.io/gitea/modules/web/middleware" 329 + func DeleteLocaleCookie 330 + 331 + package "code.gitea.io/gitea/routers/web" 332 + func NotFound 333 + 334 + package "code.gitea.io/gitea/routers/web/org" 335 + func MustEnableProjects 336 + func getActionIssues 337 + func UpdateIssueProject 338 + 339 + package "code.gitea.io/gitea/services/convert" 340 + func ToSecret 341 + 342 + package "code.gitea.io/gitea/services/forms" 343 + func (*DeadlineForm).Validate 344 + 345 + package "code.gitea.io/gitea/services/packages/alpine" 346 + func BuildAllRepositoryFiles 347 + 348 + package "code.gitea.io/gitea/services/pull" 349 + func IsCommitStatusContextSuccess 350 + 351 + package "code.gitea.io/gitea/services/repository" 352 + func GetBranchCommitID 353 + func IsErrForkAlreadyExist 354 + 355 + package "code.gitea.io/gitea/services/repository/archiver" 356 + func ArchiveRepository 357 + 358 + package "code.gitea.io/gitea/services/repository/files" 359 + func (*ContentType).String 360 + func GetFileResponseFromCommit 361 + func (*TemporaryUploadRepository).GetLastCommit 362 + func (*TemporaryUploadRepository).GetLastCommitByRef 363 + 364 + package "code.gitea.io/gitea/services/webhook" 365 + func NewNotifier 366 +
+1
.gitignore
··· 97 97 /VERSION 98 98 /.air 99 99 /.go-licenses 100 + /.cur-deadcode-out 100 101 101 102 # Snapcraft 102 103 /gitea_a*.txt
+9
Makefile
··· 22 22 SHASUM ?= shasum -a 256 23 23 HAS_GO := $(shell hash $(GO) > /dev/null 2>&1 && echo yes) 24 24 COMMA := , 25 + DIFF ?= diff --unified 25 26 26 27 XGO_VERSION := go-1.21.x 27 28 ··· 36 37 GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0 37 38 GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1.0.3 38 39 ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1.6.26 40 + DEADCODE_PACKAGE ?= golang.org/x/tools/internal/cmd/deadcode@v0.14.0 39 41 40 42 DOCKER_IMAGE ?= gitea/gitea 41 43 DOCKER_TAG ?= latest ··· 411 413 .PHONY: lint-go 412 414 lint-go: 413 415 $(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS) 416 + $(GO) run $(DEADCODE_PACKAGE) -generated=false -test code.gitea.io/gitea > .cur-deadcode-out 417 + @$(DIFF) .deadcode-out .cur-deadcode-out; \ 418 + if [ $$? -eq 1 ]; then \ 419 + echo "Please run 'make lint-go-fix' and commit the result"; \ 420 + exit 1; \ 421 + fi 414 422 415 423 .PHONY: lint-go-fix 416 424 lint-go-fix: 417 425 $(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS) --fix 426 + $(GO) run $(DEADCODE_PACKAGE) -generated=false -test code.gitea.io/gitea > .deadcode-out 418 427 419 428 # workaround step for the lint-go-windows CI task because 'go run' can not 420 429 # have distinct GOOS/GOARCH for its build and run steps
-53
modules/util/legacy.go
··· 4 4 package util 5 5 6 6 import ( 7 - "crypto/aes" 8 - "crypto/cipher" 9 - "crypto/rand" 10 - "errors" 11 7 "io" 12 8 "os" 13 9 ) ··· 40 36 } 41 37 return os.Chmod(dest, si.Mode()) 42 38 } 43 - 44 - // AESGCMEncrypt (from legacy package): encrypts plaintext with the given key using AES in GCM mode. should be replaced. 45 - func AESGCMEncrypt(key, plaintext []byte) ([]byte, error) { 46 - block, err := aes.NewCipher(key) 47 - if err != nil { 48 - return nil, err 49 - } 50 - 51 - gcm, err := cipher.NewGCM(block) 52 - if err != nil { 53 - return nil, err 54 - } 55 - 56 - nonce := make([]byte, gcm.NonceSize()) 57 - if _, err := rand.Read(nonce); err != nil { 58 - return nil, err 59 - } 60 - 61 - ciphertext := gcm.Seal(nil, nonce, plaintext, nil) 62 - return append(nonce, ciphertext...), nil 63 - } 64 - 65 - // AESGCMDecrypt (from legacy package): decrypts ciphertext with the given key using AES in GCM mode. should be replaced. 66 - func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error) { 67 - block, err := aes.NewCipher(key) 68 - if err != nil { 69 - return nil, err 70 - } 71 - 72 - gcm, err := cipher.NewGCM(block) 73 - if err != nil { 74 - return nil, err 75 - } 76 - 77 - size := gcm.NonceSize() 78 - if len(ciphertext)-size <= 0 { 79 - return nil, errors.New("ciphertext is empty") 80 - } 81 - 82 - nonce := ciphertext[:size] 83 - ciphertext = ciphertext[size:] 84 - 85 - plainText, err := gcm.Open(nil, nonce, ciphertext, nil) 86 - if err != nil { 87 - return nil, err 88 - } 89 - 90 - return plainText, nil 91 - }
-20
modules/util/legacy_test.go
··· 4 4 package util 5 5 6 6 import ( 7 - "crypto/aes" 8 - "crypto/rand" 9 7 "fmt" 10 8 "os" 11 9 "testing" ··· 37 35 assert.NoError(t, err) 38 36 assert.Equal(t, testContent, dstContent) 39 37 } 40 - 41 - func TestAESGCM(t *testing.T) { 42 - t.Parallel() 43 - 44 - key := make([]byte, aes.BlockSize) 45 - _, err := rand.Read(key) 46 - assert.NoError(t, err) 47 - 48 - plaintext := []byte("this will be encrypted") 49 - 50 - ciphertext, err := AESGCMEncrypt(key, plaintext) 51 - assert.NoError(t, err) 52 - 53 - decrypted, err := AESGCMDecrypt(key, ciphertext) 54 - assert.NoError(t, err) 55 - 56 - assert.Equal(t, plaintext, decrypted) 57 - }