Skip to content

Commit 8d04174

Browse files
committed
modes/mirror: make Updated unchanged if no new commits fetched (gogs#4341)
After sync mirror, get latest commit date and compare to current repository updated time, only update it if the commit date is newer.
1 parent 90b9f7e commit 8d04174

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/gogits/gogs/pkg/setting"
1717
)
1818

19-
const APP_VER = "0.11.5.0406"
19+
const APP_VER = "0.11.6.0406"
2020

2121
func init() {
2222
setting.AppVer = APP_VER

models/mirror.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (m *Mirror) SaveAddress(addr string) error {
184184
return fmt.Errorf("Load: %v", err)
185185
}
186186

187-
cfg.Section("remote \"origin\"").Key("url").SetValue(escapeMirrorCredentials(addr))
187+
cfg.Section(`remote "origin"`).Key("url").SetValue(escapeMirrorCredentials(addr))
188188
return cfg.SaveToIndent(configPath, "\t")
189189
}
190190

@@ -320,9 +320,19 @@ func SyncMirrors() {
320320
continue
321321
}
322322

323-
// Update repository last updated time
324-
if _, err = x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", time.Now().Unix(), m.RepoID); err != nil {
323+
// Get latest commit date and compare to current repository updated time,
324+
// update if latest commit date is newer.
325+
commitDate, err := git.GetLatestCommitDate(m.Repo.RepoPath(), "")
326+
if err != nil {
327+
log.Error(2, "GetLatestCommitDate [%s]: %v", m.RepoID, err)
328+
continue
329+
} else if commitDate.Before(m.Repo.Updated) {
330+
continue
331+
}
332+
333+
if _, err = x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", commitDate.Unix(), m.RepoID); err != nil {
325334
log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err)
335+
continue
326336
}
327337
}
328338
}

templates/.VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.11.5.0406
1+
0.11.6.0406

vendor/github.com/gogits/git-module/git.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gogits/git-module/repo.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/vendor.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@
177177
"revisionTime": "2016-08-10T03:50:02Z"
178178
},
179179
{
180-
"checksumSHA1": "XT0fyELKMKgb4XeMAtIrmi4SetM=",
180+
"checksumSHA1": "OmDPIa3NWPpl/rItpYC/Ig/m/gI=",
181181
"path": "github.com/gogits/git-module",
182-
"revision": "2a496cad1f36aed60b14844b33b68eb3edfc2718",
183-
"revisionTime": "2017-04-04T05:59:12Z"
182+
"revision": "1ebf9618c02c9480312bb55bccda7886c8d4caac",
183+
"revisionTime": "2017-04-07T00:57:10Z"
184184
},
185185
{
186186
"checksumSHA1": "D2kVXl0QpIw6t3891Sl7IM9wL+w=",

0 commit comments

Comments
 (0)