mirror of
https://github.com/gogs/gogs.git
synced 2025-12-20 15:20:01 +01:00
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.
This commit is contained in:
2
gogs.go
2
gogs.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/pkg/setting"
|
"github.com/gogits/gogs/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.11.5.0406"
|
const APP_VER = "0.11.6.0406"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ func (m *Mirror) SaveAddress(addr string) error {
|
|||||||
return fmt.Errorf("Load: %v", err)
|
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")
|
return cfg.SaveToIndent(configPath, "\t")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,9 +320,19 @@ func SyncMirrors() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update repository last updated time
|
// Get latest commit date and compare to current repository updated time,
|
||||||
if _, err = x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", time.Now().Unix(), m.RepoID); err != nil {
|
// 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)
|
log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.11.5.0406
|
0.11.6.0406
|
||||||
2
vendor/github.com/gogits/git-module/git.go
generated
vendored
2
vendor/github.com/gogits/git-module/git.go
generated
vendored
@@ -10,7 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const _VERSION = "0.6.0"
|
const _VERSION = "0.6.1"
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return _VERSION
|
return _VERSION
|
||||||
|
|||||||
15
vendor/github.com/gogits/git-module/repo.go
generated
vendored
15
vendor/github.com/gogits/git-module/repo.go
generated
vendored
@@ -278,3 +278,18 @@ func GetRepoSize(repoPath string) (*CountObject, error) {
|
|||||||
|
|
||||||
return countObject, nil
|
return countObject, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLatestCommitDate returns the date of latest commit of repository.
|
||||||
|
// If branch is empty, it returns the latest commit across all branches.
|
||||||
|
func GetLatestCommitDate(repoPath, branch string) (time.Time, error) {
|
||||||
|
cmd := NewCommand("for-each-ref", "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)")
|
||||||
|
if len(branch) > 0 {
|
||||||
|
cmd.AddArguments("refs/heads/" + branch)
|
||||||
|
}
|
||||||
|
stdout, err := cmd.RunInDir(repoPath)
|
||||||
|
if err != nil {
|
||||||
|
return time.Time{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Parse("2006-01-02 15:04:05 -0700", strings.TrimSpace(stdout))
|
||||||
|
}
|
||||||
|
|||||||
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
@@ -177,10 +177,10 @@
|
|||||||
"revisionTime": "2016-08-10T03:50:02Z"
|
"revisionTime": "2016-08-10T03:50:02Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "XT0fyELKMKgb4XeMAtIrmi4SetM=",
|
"checksumSHA1": "OmDPIa3NWPpl/rItpYC/Ig/m/gI=",
|
||||||
"path": "github.com/gogits/git-module",
|
"path": "github.com/gogits/git-module",
|
||||||
"revision": "2a496cad1f36aed60b14844b33b68eb3edfc2718",
|
"revision": "1ebf9618c02c9480312bb55bccda7886c8d4caac",
|
||||||
"revisionTime": "2017-04-04T05:59:12Z"
|
"revisionTime": "2017-04-07T00:57:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "D2kVXl0QpIw6t3891Sl7IM9wL+w=",
|
"checksumSHA1": "D2kVXl0QpIw6t3891Sl7IM9wL+w=",
|
||||||
|
|||||||
Reference in New Issue
Block a user