Skip to content

Commit 26f9a91

Browse files
committed
Revert "maybe add a special unit named as misc to sore these special repo level configs"
This reverts commit 7d8595b.
1 parent 7d8595b commit 26f9a91

File tree

9 files changed

+40
-80
lines changed

9 files changed

+40
-80
lines changed

models/repo/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit
468468
Type: tp,
469469
Config: cfg,
470470
}
471-
case unit.TypeMisc:
472-
cfg := new(MiscConfig)
471+
case unit.TypePackages:
472+
cfg := new(PackagesConfig)
473473
return &RepoUnit{
474474
Type: tp,
475475
Config: cfg,

models/repo/repo_unit.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
264264
r.Config = new(IssuesConfig)
265265
case unit.TypeActions:
266266
r.Config = new(ActionsConfig)
267+
case unit.TypePackages:
268+
r.Config = new(PackagesConfig)
267269
case unit.TypeProjects:
268270
r.Config = new(ProjectsConfig)
269-
case unit.TypeMisc:
270-
r.Config = new(MiscConfig)
271-
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypePackages:
271+
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki:
272272
fallthrough
273273
default:
274274
r.Config = new(UnitConfig)
@@ -321,23 +321,23 @@ func (r *RepoUnit) ProjectsConfig() *ProjectsConfig {
321321
return r.Config.(*ProjectsConfig)
322322
}
323323

324-
// MiscConfig returns config for unit.MiscConfig
325-
func (r *RepoUnit) MiscConfig() *MiscConfig {
326-
return r.Config.(*MiscConfig)
324+
// PackagesConfig returns config for unit.PackagesConfig
325+
func (r *RepoUnit) PackagesConfig() *PackagesConfig {
326+
return r.Config.(*PackagesConfig)
327327
}
328328

329-
// MiscConfig describes repo misc config
330-
type MiscConfig struct {
329+
// PackagesConfig describes package config
330+
type PackagesConfig struct {
331331
GoModuleSubDir string
332332
}
333333

334-
// FromDB fills up a MiscConfig from serialized format.
335-
func (cfg *MiscConfig) FromDB(bs []byte) error {
334+
// FromDB fills up a PackagesConfig from serialized format.
335+
func (cfg *PackagesConfig) FromDB(bs []byte) error {
336336
return json.UnmarshalHandleDoubleEncode(bs, &cfg)
337337
}
338338

339-
// ToDB exports a MiscConfig to a serialized format.
340-
func (cfg *MiscConfig) ToDB() ([]byte, error) {
339+
// ToDB exports a PackagesConfig to a serialized format.
340+
func (cfg *PackagesConfig) ToDB() ([]byte, error) {
341341
return json.Marshal(cfg)
342342
}
343343

models/unit/unit.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"code.gitea.io/gitea/modules/container"
1515
"code.gitea.io/gitea/modules/log"
1616
"code.gitea.io/gitea/modules/setting"
17-
"code.gitea.io/gitea/modules/util"
1817
)
1918

2019
// Type is Unit's Type
@@ -35,10 +34,6 @@ const (
3534
TypePackages // 9 Packages
3635
TypeActions // 10 Actions
3736

38-
// misc is a special uint to store special configs for a repo which is not related to any unit,
39-
// it should be considered as enabled anyway
40-
TypeMisc Type = 999 // 999 misc
41-
4237
// FIXME: TEAM-UNIT-PERMISSION: the team unit "admin" permission's design is not right, when a new unit is added in the future,
4338
// admin team won't inherit the correct admin permission for the new unit, need to have a complete fix before adding any new unit.
4439
)
@@ -70,7 +65,6 @@ var (
7065
TypeProjects,
7166
TypePackages,
7267
TypeActions,
73-
TypeMisc,
7468
}
7569

7670
// DefaultRepoUnits contains the default unit types
@@ -83,14 +77,12 @@ var (
8377
TypeProjects,
8478
TypePackages,
8579
TypeActions,
86-
TypeMisc,
8780
}
8881

8982
// ForkRepoUnits contains the default unit types for forks
9083
DefaultForkRepoUnits = []Type{
9184
TypeCode,
9285
TypePullRequests,
93-
TypeMisc,
9486
}
9587

9688
// DefaultMirrorRepoUnits contains the default unit types for mirrors
@@ -101,7 +93,6 @@ var (
10193
TypeWiki,
10294
TypeProjects,
10395
TypePackages,
104-
TypeMisc,
10596
}
10697

10798
// DefaultTemplateRepoUnits contains the default unit types for templates
@@ -113,14 +104,12 @@ var (
113104
TypeWiki,
114105
TypeProjects,
115106
TypePackages,
116-
TypeMisc,
117107
}
118108

119109
// NotAllowedDefaultRepoUnits contains units that can't be default
120110
NotAllowedDefaultRepoUnits = []Type{
121111
TypeExternalWiki,
122112
TypeExternalTracker,
123-
TypeMisc,
124113
}
125114

126115
disabledRepoUnitsAtomic atomic.Pointer[[]Type] // the units that have been globally disabled
@@ -174,11 +163,6 @@ func LoadUnitConfig() error {
174163
if len(invalidKeys) > 0 {
175164
log.Warn("Invalid keys in disabled repo units: %s", strings.Join(invalidKeys, ", "))
176165
}
177-
if slices.Contains(disabledRepoUnits, TypeMisc) {
178-
log.Warn("Misc unit should not be disabled")
179-
disabledRepoUnits = util.SliceRemoveAll(disabledRepoUnits, TypeMisc)
180-
}
181-
182166
DisabledRepoUnitsSet(disabledRepoUnits)
183167

184168
setDefaultRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultRepoUnits...)
@@ -344,15 +328,6 @@ var (
344328
perm.AccessModeOwner,
345329
}
346330

347-
UnitMisc = Unit{
348-
TypeMisc,
349-
"repo.misc",
350-
"/misc",
351-
"misc.unit.desc",
352-
999,
353-
perm.AccessModeOwner,
354-
}
355-
356331
// Units contains all the units
357332
Units = map[Type]Unit{
358333
TypeCode: UnitCode,
@@ -365,7 +340,6 @@ var (
365340
TypeProjects: UnitProjects,
366341
TypePackages: UnitPackages,
367342
TypeActions: UnitActions,
368-
TypeMisc: UnitMisc,
369343
}
370344
)
371345

options/locale/locale_en-US.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,6 @@ settings.rename_branch_from=old branch name
26292629
settings.rename_branch_to=new branch name
26302630
settings.rename_branch=Rename branch
26312631
2632-
misc = Misc
26332632
settings.go_module_sub_dir = Golang module subdirectory
26342633
settings.go_module_sub_dir_desc = The subdirectory in repository redirect for go module (which is supported since go 1.25, see <a target="_blank" rel="noopener noreferrer" href="%[1]s">%[2]s</a> for more detail)
26352634

routers/api/v1/repo/repo.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,17 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
994994

995995
if opts.HasPackages != nil && !unit_model.TypePackages.UnitGlobalDisabled() {
996996
if *opts.HasPackages {
997+
unit := repo.MustGetUnit(ctx, unit_model.TypePackages)
998+
cfg := unit.PackagesConfig()
999+
1000+
if opts.GoModuleSubDir != nil {
1001+
cfg.GoModuleSubDir = *opts.GoModuleSubDir
1002+
}
1003+
9971004
units = append(units, repo_model.RepoUnit{
9981005
RepoID: repo.ID,
9991006
Type: unit_model.TypePackages,
1007+
Config: cfg,
10001008
})
10011009
} else {
10021010
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
@@ -1014,22 +1022,6 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
10141022
}
10151023
}
10161024

1017-
miscCfg := repo.MustGetUnit(ctx, unit_model.TypeMisc).MiscConfig()
1018-
misCfgUpdated := false
1019-
1020-
if opts.GoModuleSubDir != nil {
1021-
miscCfg.GoModuleSubDir = *opts.GoModuleSubDir
1022-
misCfgUpdated = true
1023-
}
1024-
1025-
if misCfgUpdated {
1026-
units = append(units, repo_model.RepoUnit{
1027-
RepoID: repo.ID,
1028-
Type: unit_model.TypeMisc,
1029-
Config: miscCfg,
1030-
})
1031-
}
1032-
10331025
if len(units)+len(deleteUnitTypes) > 0 {
10341026
if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
10351027
ctx.APIErrorInternal(err)

routers/web/repo/setting/setting.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ func handleSettingsPostAdvanced(ctx *context.Context) {
608608
}
609609

610610
if form.EnablePackages && !unit_model.TypePackages.UnitGlobalDisabled() {
611-
units = append(units, newRepoUnit(repo, unit_model.TypePackages, nil))
611+
units = append(units, newRepoUnit(repo, unit_model.TypePackages, &repo_model.PackagesConfig{
612+
GoModuleSubDir: form.GoModuleSubDir,
613+
}))
612614
} else if !unit_model.TypePackages.UnitGlobalDisabled() {
613615
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
614616
}
@@ -638,10 +640,6 @@ func handleSettingsPostAdvanced(ctx *context.Context) {
638640
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePullRequests)
639641
}
640642

641-
miscCfg := repo.MustGetUnit(ctx, unit_model.TypeMisc).MiscConfig()
642-
miscCfg.GoModuleSubDir = form.GoModuleSubDir
643-
units = append(units, newRepoUnit(repo, unit_model.TypeMisc, miscCfg))
644-
645643
if len(units) == 0 {
646644
ctx.Flash.Error(ctx.Tr("repo.settings.update_settings_no_unit"))
647645
ctx.Redirect(ctx.Repo.RepoLink + "/settings")

services/context/context.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext {
119119
"RepoUnitTypeProjects": unit.TypeProjects,
120120
"RepoUnitTypePackages": unit.TypePackages,
121121
"RepoUnitTypeActions": unit.TypeActions,
122-
"RepoUnitTypeMisc": unit.TypeMisc,
123122
}
124123
return tmplCtx
125124
}

services/context/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ func EarlyResponseForGoGetMeta(ctx *Context) {
346346

347347
// GetGoModuleSubDirConfig retrieves the subdirectory configuration for a Go module.
348348
func GetGoModuleSubDirConfig(ctx *Context, repo *repo_model.Repository) string {
349-
miscCfg := repo.MustGetUnit(ctx, unit_model.TypeMisc).MiscConfig()
349+
pkgCfg := repo.MustGetUnit(ctx, unit_model.TypePackages).PackagesConfig()
350350

351-
return strings.TrimSpace(miscCfg.GoModuleSubDir)
351+
return strings.TrimSpace(pkgCfg.GoModuleSubDir)
352352
}
353353

354354
// RedirectToRepo redirect to a differently-named repository

templates/repo/settings/options.tmpl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,28 @@
499499
</div>
500500
</div>
501501

502+
<div class="divider"></div>
502503
{{$isPackagesEnabled := .Repository.UnitEnabled ctx ctx.Consts.RepoUnitTypePackages}}
503504
{{$isPackagesGlobalDisabled := ctx.Consts.RepoUnitTypePackages.UnitGlobalDisabled}}
505+
{{$pkgUnit := .Repository.MustGetUnit ctx ctx.Consts.RepoUnitTypePackages}}
504506
<div class="inline field">
505507
<label>{{ctx.Locale.Tr "repo.packages"}}</label>
506508
<div class="ui checkbox{{if $isPackagesGlobalDisabled}} disabled{{end}}"{{if $isPackagesGlobalDisabled}} data-tooltip-content="{{ctx.Locale.Tr "repo.unit_disabled"}}"{{end}}>
507-
<input class="enable-system" name="enable_packages" type="checkbox" {{if $isPackagesEnabled}}checked{{end}}>
509+
<input class="enable-system" name="enable_packages" type="checkbox" data-target="#packages_box" {{if $isPackagesEnabled}}checked{{end}}>
508510
<label>{{ctx.Locale.Tr "repo.settings.packages_desc"}}</label>
509511
</div>
510512
</div>
511513

514+
<div class="field{{if not $isPackagesEnabled}} disabled{{end}}" id="packages_box">
515+
<div class="field tw-pl-4 {{if $isPackagesGlobalDisabled}}disabled{{end}}">
516+
<label for="go_module_sub_dir">{{ctx.Locale.Tr "repo.settings.go_module_sub_dir"}}</label>
517+
<input id="go_module_sub_dir" name="go_module_sub_dir" value="{{$pkgUnit.PackagesConfig.GoModuleSubDir}}">
518+
<p class="help">{{ctx.Locale.Tr "repo.settings.go_module_sub_dir_desc" "https://github.com/golang/go/commit/835e36fc7f631f74233edfd4ab43b6b56833db86" "github.com/golang/go@835e36fc7f"}}</p>
519+
</div>
520+
</div>
521+
522+
<div class="divider"></div>
523+
512524
{{if .EnableActions}}
513525
{{$isActionsEnabled := .Repository.UnitEnabled ctx ctx.Consts.RepoUnitTypeActions}}
514526
{{$isActionsGlobalDisabled := ctx.Consts.RepoUnitTypeActions.UnitGlobalDisabled}}
@@ -647,20 +659,6 @@
647659
</div>
648660
{{end}}
649661

650-
<div class="divider"></div>
651-
{{$miscUnit := .Repository.MustGetUnit ctx ctx.Consts.RepoUnitTypeMisc}}
652-
<div class="inline field">
653-
<label>{{ctx.Locale.Tr "repo.misc"}}</label>
654-
</div>
655-
656-
<div class="field" id="misc_box">
657-
<div class="field tw-pl-4">
658-
<label for="go_module_sub_dir">{{ctx.Locale.Tr "repo.settings.go_module_sub_dir"}}</label>
659-
<input id="go_module_sub_dir" name="go_module_sub_dir" value="{{$miscUnit.MiscConfig.GoModuleSubDir}}">
660-
<p class="help">{{ctx.Locale.Tr "repo.settings.go_module_sub_dir_desc" "https://github.com/golang/go/commit/835e36fc7f631f74233edfd4ab43b6b56833db86" "github.com/golang/go@835e36fc7f"}}</p>
661-
</div>
662-
</div>
663-
664662
<div class="divider"></div>
665663
<div class="field">
666664
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>

0 commit comments

Comments
 (0)