Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable automatic mirror syncing. #5242

Merged
merged 2 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add option to disable automatic mirror syncing.
Setting the interval to 0 will disable to automatic syncing.
  • Loading branch information
cez81 committed Oct 31, 2018
commit 538d6a603e109267a336ace102368901d66c6120
7 changes: 6 additions & 1 deletion models/repo_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func (m *Mirror) AfterLoad(session *xorm.Session) {

// ScheduleNextUpdate calculates and sets next update time.
func (m *Mirror) ScheduleNextUpdate() {
m.NextUpdateUnix = util.TimeStampNow().AddDuration(m.Interval)
if m.Interval != 0 {
m.NextUpdateUnix = util.TimeStampNow().AddDuration(m.Interval)
} else {
m.NextUpdateUnix = 0
}
}

func remoteAddress(repoPath string) (string, error) {
Expand Down Expand Up @@ -302,6 +306,7 @@ func MirrorUpdate() {

if err := x.
Where("next_update_unix<=?", time.Now().Unix()).
And("next_update_unix!=0").
Iterate(new(Mirror), func(idx int, bean interface{}) error {
m := bean.(*Mirror)
if m.Repo == nil {
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ create_repo = Create Repository
default_branch = Default Branch
mirror_prune = Prune
mirror_prune_desc = Remove obsolete remote-tracking references
mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's')
mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync.
mirror_interval_invalid = The mirror interval is not valid.
mirror_address = Clone From URL
mirror_address_desc = Include any required authorization credentials in the URL.
Expand Down
8 changes: 6 additions & 2 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
}

interval, err := time.ParseDuration(form.Interval)
if err != nil || interval < setting.Mirror.MinInterval {
if err != nil && (interval != 0 || interval < setting.Mirror.MinInterval) {
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
} else {
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
ctx.Repo.Mirror.Interval = interval
ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval)
if interval != 0 {
ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval)
} else {
ctx.Repo.Mirror.NextUpdateUnix = 0
}
if err := models.UpdateMirror(ctx.Repo.Mirror); err != nil {
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
return
Expand Down