Skip to content

Commit 599adde

Browse files
cez81techknowlogick
authored andcommitted
Add option to disable automatic mirror syncing. (#5242)
Setting the interval to 0 will disable to automatic syncing.
1 parent de8f981 commit 599adde

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

models/repo_mirror.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ func (m *Mirror) AfterLoad(session *xorm.Session) {
6363

6464
// ScheduleNextUpdate calculates and sets next update time.
6565
func (m *Mirror) ScheduleNextUpdate() {
66-
m.NextUpdateUnix = util.TimeStampNow().AddDuration(m.Interval)
66+
if m.Interval != 0 {
67+
m.NextUpdateUnix = util.TimeStampNow().AddDuration(m.Interval)
68+
} else {
69+
m.NextUpdateUnix = 0
70+
}
6771
}
6872

6973
func remoteAddress(repoPath string) (string, error) {
@@ -302,6 +306,7 @@ func MirrorUpdate() {
302306

303307
if err := x.
304308
Where("next_update_unix<=?", time.Now().Unix()).
309+
And("next_update_unix!=0").
305310
Iterate(new(Mirror), func(idx int, bean interface{}) error {
306311
m := bean.(*Mirror)
307312
if m.Repo == nil {

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ create_repo = Create Repository
524524
default_branch = Default Branch
525525
mirror_prune = Prune
526526
mirror_prune_desc = Remove obsolete remote-tracking references
527-
mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's')
527+
mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync.
528528
mirror_interval_invalid = The mirror interval is not valid.
529529
mirror_address = Clone From URL
530530
mirror_address_desc = Include any required authorization credentials in the URL.

routers/repo/setting.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
117117
}
118118

119119
interval, err := time.ParseDuration(form.Interval)
120-
if err != nil || interval < setting.Mirror.MinInterval {
120+
if err != nil && (interval != 0 || interval < setting.Mirror.MinInterval) {
121121
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
122122
} else {
123123
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
124124
ctx.Repo.Mirror.Interval = interval
125-
ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval)
125+
if interval != 0 {
126+
ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval)
127+
} else {
128+
ctx.Repo.Mirror.NextUpdateUnix = 0
129+
}
126130
if err := models.UpdateMirror(ctx.Repo.Mirror); err != nil {
127131
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
128132
return

0 commit comments

Comments
 (0)