Skip to content

Remove dead code identified by deadcode tool#37271

Merged
silverwind merged 8 commits intogo-gitea:mainfrom
silverwind:remove-dead-code
Apr 20, 2026
Merged

Remove dead code identified by deadcode tool#37271
silverwind merged 8 commits intogo-gitea:mainfrom
silverwind:remove-dead-code

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Apr 18, 2026

Ran deadcode (-test ./...) to find functions, methods and error types unreachable from any call path (including tests), and removed the truly-dead ones.

Unused list/load helpers on RunList, ScheduleList, BranchList.

Never-called CRUD/query helpers:

  • CountUserFeeds, HasDeployKey, WebAuthnCredentials, GetPinnedIssueIDs, UpdateTeamUnits, UpdateColumnSorting, RemoveAllWithNotice, DumpQueryResult, RemoveAllUserBadges, GetBadgeByID, UpdateEmailAddress, CommitsCountBetween, GitConfigGet, dbfs.Create

Error types never constructed — struct + Error/Unwrap + IsErr* helper + now-always-false caller branches:

  • ErrGPGKeyAccessDenied (+ 2 caller branches in routers/api/v1/user/gpg_key.go)
  • ErrNewIssueInsert (+ || IsErrNewIssueInsert(err) in models/issues/{pull,issue_update}.go)
  • ErrUserInactive (+ 2 caller branches in routers/web/auth/{auth,linkaccount}.go)
  • ErrInvalidConfiguration (no callers)

Unused IsErr* helpers (error struct is still constructed, just never type-checked):

  • IsErrUnknownDependencyType, IsErrIssueIsOpen, IsErrTopicNotExist, IsErrExternalLoginUserAlreadyExist, IsErrExternalLoginUserNotExist, IsErrUserSettingIsNotExist, IsErrSHANotFound

Unused helpers / option funcs / route handlers:

  • WithJobResults, SearchMembersOptions.ToConds, RunList.GetRepoIDs, HostMatchList.AppendPattern, Event.String, ContentType.String, GlodmarkRender.Renderer, Manager.GetLogRecorder, DeleteLocaleCookie, Manager.{Err,Value,Deadline,TerminateContext}, ParseCreateHook, ParsePushHook, routers/web.NotFound, MustEnableProjects, RedirectToDefaultSetting, UserIDAssignmentAPI, ToSecret, DeadlineForm.Validate

This PR was written with the help of Claude Opus 4.7

Ran `deadcode -test ./...` and removed functions, methods and error
types that are unreachable from any call path, including tests. Where
an error type was never constructed, the corresponding IsErr* helper
and its always-false caller branches are removed as well.

Dropped:
- Unused list/load helpers on RunList, ScheduleList, BranchList
- Never-called CRUD/query helpers: CountUserFeeds, HasDeployKey,
  WebAuthnCredentials, GetPinnedIssueIDs, UpdateTeamUnits,
  UpdateColumnSorting, RemoveAllWithNotice, DumpQueryResult,
  RemoveAllUserBadges, GetBadgeByID, UpdateEmailAddress,
  CommitsCountBetween, GitConfigGet, dbfs.Create
- Unused error types never constructed: ErrGPGKeyAccessDenied,
  ErrNewIssueInsert, ErrUserInactive, ErrInvalidConfiguration
  (and the always-false caller branches that checked them)
- Unused IsErr* helpers: IsErrUnknownDependencyType, IsErrIssueIsOpen,
  IsErrTopicNotExist, IsErrExternalLoginUser{AlreadyExist,NotExist},
  IsErrUserSettingIsNotExist, IsErrSHANotFound
- Unused helpers and option funcs: WithJobResults, SearchMembersOptions.ToConds,
  RunList.GetRepoIDs, HostMatchList.AppendPattern, Event.String,
  ContentType.String, GlodmarkRender.Renderer, Manager.GetLogRecorder,
  DeleteLocaleCookie, Manager.{Err,Value,Deadline,TerminateContext},
  ParseCreateHook, ParsePushHook, NotFound (routers/web), MustEnableProjects,
  RedirectToDefaultSetting, UserIDAssignmentAPI, ToSecret,
  DeadlineForm.Validate

No behaviour change — all removed code paths were unreachable.

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 18, 2026
@silverwind silverwind added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Apr 18, 2026
@silverwind silverwind requested a review from Copilot April 18, 2026 01:52
Comment thread models/unittest/unit_tests.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes unreachable (“dead”) code identified by the deadcode -test ./... tool across the codebase to reduce maintenance surface and simplify control flow.

Changes:

  • Removed unused exported helpers/types (list/load helpers, CRUD/query helpers, option funcs, and route handlers).
  • Deleted never-constructed error types and corresponding now-always-false branches in callers.
  • Cleaned up related imports and small wrappers/accessors that are no longer referenced.

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
services/repository/files/tree.go Removed unused IsErrSHANotFound helper.
services/repository/files/content.go Removed unused ContentType.String method.
services/forms/repo_form.go Removed unused DeadlineForm and validation method.
services/convert/secret.go Deleted unused Secret-to-API conversion helper.
services/context/user.go Removed unused API user assignment middleware (UserIDAssignmentAPI).
routers/web/shared/actions/runners.go Removed unused redirect helper.
routers/web/org/projects.go Removed unused “projects enabled” guard helper.
routers/web/home.go Removed unused NotFound helper wrapper.
routers/web/auth/linkaccount.go Removed unreachable inactive-user error branch.
routers/web/auth/auth.go Removed unreachable inactive-user error branch.
routers/api/v1/user/gpg_key.go Removed unreachable GPG access-denied branches and simplified error handling.
modules/web/middleware/locale.go Removed unused locale-cookie deletion helper.
modules/tailmsg/talimsg.go Removed unused log recorder accessor.
modules/structs/hook.go Removed unused webhook payload parsing helpers.
modules/storage/storage.go Removed unused invalid-configuration error type and checker.
modules/markup/markdown/markdown.go Removed unused renderer accessor.
modules/hostmatcher/hostmatcher.go Removed unused pattern append helper.
modules/graceful/manager.go Removed unused context-like methods on Manager; clarified Done comment.
modules/graceful/context.go Removed unused TerminateContext accessor.
modules/gitrepo/config.go Removed unused GitConfigGet helper and related import.
modules/gitrepo/commit.go Removed unused CommitsCountBetween helper.
modules/eventsource/event.go Removed unused Event.String method and related import.
modules/actions/jobparser/jobparser.go Removed unused parse option (WithJobResults).
models/user/setting.go Removed unused error type-check helper.
models/user/external_login_user.go Removed unused error type-check helpers.
models/user/error.go Removed never-constructed inactive-user error type and helper.
models/user/email_address.go Removed unused UpdateEmailAddress helper.
models/user/badge.go Removed unused badge helpers (RemoveAllUserBadges, GetBadgeByID).
models/unittest/unit_tests.go Removed unused query dump debugging helper and imports.
models/system/notice.go Removed unused filesystem removal helper and import.
models/repo/topic.go Removed unused error type-check helper.
models/project/column.go Removed unused column sorting updater.
models/organization/team_user.go Removed unused condition-builder helper.
models/organization/team_unit.go Removed unused team-units update helper.
models/issues/pull.go Removed unreachable ErrNewIssueInsert branch from error handling.
models/issues/issue_update.go Removed unused error type-check helper and unreachable ErrNewIssueInsert branch.
models/issues/issue_pin.go Removed unused pinned-IDs helper.
models/issues/issue.go Removed never-constructed ErrNewIssueInsert type and helper.
models/issues/dependency.go Removed unused error type-check helper.
models/git/branch_list.go Removed unused repo-loading helper and import.
models/dbfs/dbfs.go Removed unused Create helper.
models/auth/webauthn.go Removed unused WebAuthnCredentials helper.
models/asymkey/ssh_key_deploy.go Removed unused deploy-key existence helper.
models/asymkey/error.go Removed never-constructed GPG access-denied error type and helper.
models/activities/action_list.go Removed unused feed-count helper.
models/actions/schedule_list.go Removed unused list/load helpers and imports.
models/actions/run_list.go Removed unused repo-IDs/load-repos helpers and import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/structs/hook.go
Comment thread modules/graceful/manager.go Outdated
Comment thread modules/graceful/context.go
Comment thread models/dbfs/dbfs.go
Comment thread models/unittest/unit_tests.go
Comment thread modules/graceful/context.go
Comment thread modules/tailmsg/talimsg.go
@wxiaoguang wxiaoguang marked this pull request as draft April 18, 2026 04:25
- `DumpQueryResult`: debug helper (silverwind, wxiaoguang)
- `ParseCreateHook`/`ParsePushHook`: keep public API surface (Copilot)
- `Manager.Err`/`Value`/`Deadline`: preserve `context.Context` interface (Copilot)
- `Manager.TerminateContext`: referenced by shutdown docs (Copilot, wxiaoguang)
- `dbfs.Create`: consistency with `os.Create` (wxiaoguang)
- `Manager.GetLogRecorder`: reserved for future use (wxiaoguang)

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@silverwind
Copy link
Copy Markdown
Member Author

All mentioned code restored.

@silverwind silverwind marked this pull request as ready for review April 19, 2026 12:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread routers/api/v1/user/gpg_key.go
Comment thread routers/web/auth/auth.go
Comment thread routers/web/auth/linkaccount.go
Comment thread routers/api/v1/user/gpg_key.go
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 20, 2026
After removing the dead IsErrGPGKeyAccessDenied branch in the previous
commit, the DeleteGPGKey handler no longer returns 403, so drop it
from the documented responses.

Caught by Copilot review.

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 20, 2026
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 20, 2026
@silverwind silverwind enabled auto-merge (squash) April 20, 2026 06:46
@silverwind silverwind merged commit aba8728 into go-gitea:main Apr 20, 2026
26 checks passed
@silverwind silverwind deleted the remove-dead-code branch April 20, 2026 07:52
@GiteaBot GiteaBot added this to the 1.27.0 milestone Apr 20, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 20, 2026
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 20, 2026
…-lang

* origin/main:
  Update go js dependencies (go-gitea#37312)
  Update GitHub Actions to latest major versions (go-gitea#37313)
  Revert "Add WebKit to e2e test matrix (go-gitea#37298)" (go-gitea#37315)
  Add `form-fetch-action` to some forms, fix "fetch action" resp bug (go-gitea#37305)
  Move heatmap to first-party code (go-gitea#37262)
  Use updated yaml fields for snapcraft (go-gitea#37318)
  Remove dead code identified by `deadcode` tool (go-gitea#37271)
  Enable strict TypeScript, add `errorMessage` helper (go-gitea#37292)
  Fix vite manifest update masking build errors (go-gitea#37279)
  bump snapcraft base (go-gitea#37301)

# Conflicts:
#	web_src/js/modules/errors.ts
silverwind added a commit to 6543-forks/gitea that referenced this pull request Apr 21, 2026
…n-better

* origin/main: (645 commits)
  When the requested arch rpm is missing fall back to noarch (go-gitea#37236)
  Fix `relative-time` error and improve global error handler (go-gitea#37241)
  Enhance styling in actions page (go-gitea#37323)
  fix(oauth): Error on auth sources with spaces (go-gitea#37327)
  Fix actions concurrency groups cross-branch leak (go-gitea#37311)
  Fix bug when accessing user badges (go-gitea#37321)
  Fix AppFullLink (go-gitea#37325)
  Update go js dependencies (go-gitea#37312)
  Update GitHub Actions to latest major versions (go-gitea#37313)
  Revert "Add WebKit to e2e test matrix (go-gitea#37298)" (go-gitea#37315)
  Add `form-fetch-action` to some forms, fix "fetch action" resp bug (go-gitea#37305)
  Move heatmap to first-party code (go-gitea#37262)
  Use updated yaml fields for snapcraft (go-gitea#37318)
  Remove dead code identified by `deadcode` tool (go-gitea#37271)
  Enable strict TypeScript, add `errorMessage` helper (go-gitea#37292)
  Fix vite manifest update masking build errors (go-gitea#37279)
  bump snapcraft base (go-gitea#37301)
  Add WebKit to e2e test matrix (go-gitea#37298)
  Don't add useless labels which will bother changelog generation (go-gitea#37267)
  Fix Repository transferring page (go-gitea#37277)
  ...

# Conflicts:
#	options/locale/locale_en-US.ini
#	templates/package/content/debian.tmpl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/refactoring Existing code has been cleaned up. There should be no new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants