Skip to content

Commit 95b18eb

Browse files
lunnywxiaoguang
andauthored
Remove unnecessary code and fix comments (#35761)
Follow #35459, #32562 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent d69eede commit 95b18eb

File tree

14 files changed

+30
-48
lines changed

14 files changed

+30
-48
lines changed

models/perm/access/repo_permission.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ func GetActionsUserRepoPermission(ctx context.Context, repo *repo_model.Reposito
276276
// The task repo can access the current repo only if the task repo is private and
277277
// the owner of the task repo is a collaborative owner of the current repo.
278278
// FIXME allow public repo read access if tokenless pull is enabled
279+
// FIXME should owner's visibility also be considered here?
279280
return perm, nil
280281
}
281282
accessMode = perm_model.AccessModeRead

routers/api/v1/repo/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func CreateBranch(ctx *context.APIContext) {
243243
}
244244
}
245245

246-
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, oldCommit.ID.String(), opt.BranchName)
246+
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, oldCommit.ID.String(), opt.BranchName)
247247
if err != nil {
248248
if git_model.IsErrBranchNotExist(err) {
249249
ctx.APIError(http.StatusNotFound, "The old branch does not exist")
@@ -434,7 +434,7 @@ func RenameBranch(ctx *context.APIContext) {
434434
return
435435
}
436436

437-
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, oldName, opt.Name)
437+
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, oldName, opt.Name)
438438
if err != nil {
439439
switch {
440440
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):

routers/web/repo/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ func CreateBranch(ctx *context.Context) {
194194
}
195195
err = release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, target, form.NewBranchName, "")
196196
} else if ctx.Repo.RefFullName.IsBranch() {
197-
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.BranchName, form.NewBranchName)
197+
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
198198
} else {
199-
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.CommitID, form.NewBranchName)
199+
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
200200
}
201201
if err != nil {
202202
if release_service.IsErrProtectedTagName(err) {

routers/web/repo/setting/protected_branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func RenameBranchPost(ctx *context.Context) {
337337
return
338338
}
339339

340-
msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, ctx.Repo.GitRepo, form.From, form.To)
340+
msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, form.From, form.To)
341341
if err != nil {
342342
switch {
343343
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):

routers/web/repo/setting/setting.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ func handleSettingsPostUpdate(ctx *context.Context) {
207207
repo.Website = form.Website
208208
repo.IsTemplate = form.Template
209209

210-
// Visibility of forked repository is forced sync with base repository.
211-
if repo.IsFork {
212-
form.Private = repo.BaseRepo.IsPrivate || repo.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate
213-
}
214-
215210
if err := repo_service.UpdateRepository(ctx, repo, false); err != nil {
216211
ctx.ServerError("UpdateRepository", err)
217212
return

services/forms/repo_form.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ type RepoSettingForm struct {
104104
PushMirrorPassword string
105105
PushMirrorSyncOnCommit bool
106106
PushMirrorInterval string
107-
Private bool
108107
Template bool
109108
EnablePrune bool
110109

@@ -148,10 +147,6 @@ type RepoSettingForm struct {
148147
AllowOnlyContributorsToTrackTime bool
149148
EnableIssueDependencies bool
150149

151-
EnableActions bool
152-
153-
IsArchived bool
154-
155150
// Signing Settings
156151
TrustModel string
157152

services/repository/branch.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ import (
3838
)
3939

4040
// CreateNewBranch creates a new repository branch
41-
func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, oldBranchName, branchName string) (err error) {
41+
func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) {
4242
branch, err := git_model.GetBranch(ctx, repo.ID, oldBranchName)
4343
if err != nil {
4444
return err
4545
}
4646

47-
return CreateNewBranchFromCommit(ctx, doer, repo, gitRepo, branch.CommitID, branchName)
47+
return CreateNewBranchFromCommit(ctx, doer, repo, branch.CommitID, branchName)
4848
}
4949

5050
// Branch contains the branch information
@@ -374,7 +374,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames,
374374
}
375375

376376
// CreateNewBranchFromCommit creates a new repository branch
377-
func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, commitID, branchName string) (err error) {
377+
func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commitID, branchName string) (err error) {
378378
err = repo.MustNotBeArchived()
379379
if err != nil {
380380
return err
@@ -399,7 +399,7 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo
399399
}
400400

401401
// RenameBranch rename a branch
402-
func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) {
402+
func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, from, to string) (string, error) {
403403
err := repo.MustNotBeArchived()
404404
if err != nil {
405405
return "", err
@@ -413,8 +413,12 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
413413
return "target_exist", nil
414414
}
415415

416-
if exist, _ := git_model.IsBranchExist(ctx, repo.ID, from); !exist {
417-
return "from_not_exist", nil
416+
fromBranch, err := git_model.GetBranch(ctx, repo.ID, from)
417+
if err != nil {
418+
if git_model.IsErrBranchNotExist(err) {
419+
return "from_not_exist", nil
420+
}
421+
return "", err
418422
}
419423

420424
perm, err := access_model.GetUserRepoPermission(ctx, repo, doer)
@@ -472,14 +476,9 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
472476
}); err != nil {
473477
return "", err
474478
}
475-
refNameTo := git.RefNameFromBranch(to)
476-
refID, err := gitRepo.GetRefCommitID(refNameTo.String())
477-
if err != nil {
478-
return "", err
479-
}
480479

481480
notify_service.DeleteRef(ctx, doer, repo, git.RefNameFromBranch(from))
482-
notify_service.CreateRef(ctx, doer, repo, refNameTo, refID)
481+
notify_service.CreateRef(ctx, doer, repo, git.RefNameFromBranch(to), fromBranch.CommitID)
483482

484483
return "", nil
485484
}

templates/admin/notice.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{{.CsrfTokenHtml}}
3838
<button type="submit" class="ui red small button">{{ctx.Locale.Tr "admin.notices.delete_all"}}</button>
3939
</form>
40-
<div class="ui floating upward dropdown small button">{{/* TODO: Make this dropdown accessible */}}
40+
<div class="ui floating upward dropdown small button">
4141
<span class="text">{{ctx.Locale.Tr "admin.notices.operations"}}</span>
4242
<div class="menu">
4343
<div class="item select action" data-action="select-all">

templates/projects/new.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</div>
1919
<div class="field">
2020
<label>{{ctx.Locale.Tr "repo.projects.description"}}</label>
21-
{{/* TODO: repo-level project and org-level project have different behaviros to render */}}
21+
{{/* TODO: repo-level project and org-level project have different behaviors to render */}}
2222
{{/* the "Repository" is nil when the project is org-level */}}
2323
{{template "shared/combomarkdowneditor" (dict
2424
"MarkdownPreviewInRepo" $.Repository

templates/repo/issue/branch_selector_field.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
PR: https://github.com/go-gitea/gitea/pull/32744
33

44
The Issue.Ref was added by Add possibility to record branch or tag information in an issue (#780)
5-
After 8 years, this "branch selector" does nothing more than saving the branch/tag name into database and displays it.
5+
After 8 years, this "branch selector" does nothing more than saving the branch/tag name into database and displays it,
6+
or sometimes auto-close a ref-matched issue by a commit message when CloseIssuesViaCommitInAnyBranch=false.
67

78
There are still users using it:
89
* @didim99: it is a really useful feature to specify a branch in which issue found.

0 commit comments

Comments
 (0)