Skip to content

Commit d35bfcc

Browse files
committed
fetch LFS on mirror update
1 parent 4c649db commit d35bfcc

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

models/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ type Repository struct {
219219
IsEmpty bool `xorm:"INDEX"`
220220
IsArchived bool `xorm:"INDEX"`
221221
IsMirror bool `xorm:"INDEX"`
222+
LFS bool `yaml:"lfs"`
223+
LFSServer string `yaml:"lfs_server"`
222224
*Mirror `xorm:"-"`
223225
Status RepositoryStatus `xorm:"NOT NULL DEFAULT 0"`
224226

modules/migrations/base/repo.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ package base
99
type Repository struct {
1010
Name string
1111
Owner string
12-
IsPrivate bool `yaml:"is_private"`
13-
IsMirror bool `yaml:"is_mirror"`
12+
IsPrivate bool `yaml:"is_private"`
13+
IsMirror bool `yaml:"is_mirror"`
14+
LFS bool `yaml:"lfs"`
15+
LFSServer string `yaml:"lfs_server"`
1416
Description string
1517
CloneURL string `yaml:"clone_url"`
1618
OriginalURL string `yaml:"original_url"`

modules/migrations/migrate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
140140
}
141141
repo.IsPrivate = opts.Private
142142
repo.IsMirror = opts.Mirror
143+
repo.LFS = opts.LFS
144+
repo.LFSServer = opts.LFSServer
143145
if opts.Description != "" {
144146
repo.Description = opts.Description
145147
}

services/mirror/mirror.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
206206
}
207207

208208
// runSync returns true if sync finished without error.
209-
func runSync(m *models.Mirror) ([]*mirrorSyncResult, bool) {
209+
func runSync(ctx context.Context, m *models.Mirror) ([]*mirrorSyncResult, bool) {
210210
repoPath := m.Repo.RepoPath()
211211
wikiPath := m.Repo.UncycloPath()
212212
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
@@ -253,13 +253,20 @@ func runSync(m *models.Mirror) ([]*mirrorSyncResult, bool) {
253253
log.Error("OpenRepository: %v", err)
254254
return nil, false
255255
}
256+
defer gitRepo.Close()
257+
258+
if m.Repo.LFS {
259+
log.Trace("SyncMirrors [repo: %-v]: fetching LFS files...", m.Repo)
260+
err := repo_module.FetchMissingLFSFilesToContentStore(ctx, m.Repo, Username(m), gitRepo, m.Repo.LFSServer, false)
261+
if err != nil {
262+
log.Error("Failed to fetch LFS files %v:\nErr: %v", m.Repo, err)
263+
}
264+
}
256265

257266
log.Trace("SyncMirrors [repo: %-v]: syncing releases with tags...", m.Repo)
258267
if err = repo_module.SyncReleasesWithTags(m.Repo, gitRepo); err != nil {
259-
gitRepo.Close()
260268
log.Error("Failed to synchronize tags to releases for repository: %v", err)
261269
}
262-
gitRepo.Close()
263270

264271
log.Trace("SyncMirrors [repo: %-v]: updating size of repository", m.Repo)
265272
if err := m.Repo.UpdateSize(models.DefaultDBContext()); err != nil {
@@ -378,12 +385,12 @@ func SyncMirrors(ctx context.Context) {
378385
mirrorQueue.Close()
379386
return
380387
case repoID := <-mirrorQueue.Queue():
381-
syncMirror(repoID)
388+
syncMirror(ctx, repoID)
382389
}
383390
}
384391
}
385392

386-
func syncMirror(repoID string) {
393+
func syncMirror(ctx context.Context, repoID string) {
387394
log.Trace("SyncMirrors [repo_id: %v]", repoID)
388395
defer func() {
389396
err := recover()
@@ -403,7 +410,7 @@ func syncMirror(repoID string) {
403410
}
404411

405412
log.Trace("SyncMirrors [repo: %-v]: Running Sync", m.Repo)
406-
results, ok := runSync(m)
413+
results, ok := runSync(ctx, m)
407414
if !ok {
408415
return
409416
}

0 commit comments

Comments
 (0)