From 8d0417497b39aa196400d39c99bbd79cfb364f9f Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 6 Apr 2017 20:58:57 -0400 Subject: 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. --- models/mirror.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'models/mirror.go') 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 } } } -- cgit v1.2.3