diff options
author | Unknwon <u@gogs.io> | 2017-04-06 20:58:57 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-04-06 20:58:57 -0400 |
commit | 8d0417497b39aa196400d39c99bbd79cfb364f9f (patch) | |
tree | e09028f02c5732ab8c3f9140dfcba488d41809df /models/mirror.go | |
parent | 90b9f7e08ca2e027cc587199537aa653ddd94d91 (diff) |
modes/mirror: make Updated unchanged if no new commits fetched (#4341)
After sync mirror, get latest commit date and compare to current
repository updated time, only update it if the commit date is newer.
Diffstat (limited to 'models/mirror.go')
-rw-r--r-- | models/mirror.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/models/mirror.go b/models/mirror.go index 30a0155f..778632b4 100644 --- a/models/mirror.go +++ b/models/mirror.go @@ -184,7 +184,7 @@ func (m *Mirror) SaveAddress(addr string) error { return fmt.Errorf("Load: %v", err) } - cfg.Section("remote \"origin\"").Key("url").SetValue(escapeMirrorCredentials(addr)) + cfg.Section(`remote "origin"`).Key("url").SetValue(escapeMirrorCredentials(addr)) return cfg.SaveToIndent(configPath, "\t") } @@ -320,9 +320,19 @@ func SyncMirrors() { continue } - // Update repository last updated time - if _, err = x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", time.Now().Unix(), m.RepoID); err != nil { + // Get latest commit date and compare to current repository updated time, + // update if latest commit date is newer. + commitDate, err := git.GetLatestCommitDate(m.Repo.RepoPath(), "") + if err != nil { + log.Error(2, "GetLatestCommitDate [%s]: %v", m.RepoID, err) + continue + } else if commitDate.Before(m.Repo.Updated) { + continue + } + + if _, err = x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", commitDate.Unix(), m.RepoID); err != nil { log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err) + continue } } } |