@@ -100,7 +100,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models.
100
100
defer gitRepo .Close ()
101
101
102
102
if opts .LFS {
103
- err := FetchLFSFilesToContentStore (ctx , repo , u .Name , gitRepo , opts .LFSServer , opts .LFSFetchOlder )
103
+ err := FetchMissingLFSFilesToContentStore (ctx , repo , u .Name , gitRepo , opts .LFSServer , opts .LFSFetchOlder )
104
104
if err != nil {
105
105
return repo , fmt .Errorf ("Failed to fetch LFS files: %v" , err )
106
106
}
@@ -174,15 +174,15 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models.
174
174
return repo , err
175
175
}
176
176
177
- func FetchLFSFilesToContentStore (ctx context.Context , repo * models.Repository , userName string , gitRepo * git.Repository , LFSServer string , LFSFetchOlder bool ) error {
178
- fetchingMetaObjects := [ ]* models.LFSMetaObject {}
177
+ func FetchMissingLFSFilesToContentStore (ctx context.Context , repo * models.Repository , userName string , gitRepo * git.Repository , LFSServer string , LFSFetchOlder bool ) error {
178
+ fetchingMetaObjectsSet := make ( map [ string ]* models.LFSMetaObject )
179
179
var err error
180
180
181
181
// scan repo for pointer files
182
182
headBranch , _ := gitRepo .GetHEADBranch ()
183
183
headCommit , _ := gitRepo .GetCommit (headBranch .Name )
184
184
185
- err = FindLFSMetaObjectsBelowMaxFileSize (headCommit , userName , repo , & fetchingMetaObjects )
185
+ err = FindLFSMetaObjectsBelowMaxFileSizeWithMissingFiles (headCommit , userName , repo , & fetchingMetaObjectsSet )
186
186
if err != nil {
187
187
log .Error ("Failed to access git LFS meta objects on commit %s: %v" , headCommit .ID .String (), err )
188
188
return err
@@ -199,14 +199,19 @@ func FetchLFSFilesToContentStore(ctx context.Context, repo *models.Repository, u
199
199
200
200
for e := commitsList .Front (); e != nil ; e = e .Next () {
201
201
commit := e .Value .(* git.Commit )
202
- err = FindLFSMetaObjectsBelowMaxFileSize (commit , userName , repo , & fetchingMetaObjects )
202
+ err = FindLFSMetaObjectsBelowMaxFileSizeWithMissingFiles (commit , userName , repo , & fetchingMetaObjectsSet )
203
203
if err != nil {
204
204
log .Error ("Failed to access git LFS meta objects on commit %s: %v" , commit .ID .String (), err )
205
205
return err
206
206
}
207
207
}
208
208
}
209
209
210
+ fetchingMetaObjects := []* models.LFSMetaObject {}
211
+ for metaID := range fetchingMetaObjectsSet {
212
+ fetchingMetaObjects = append (fetchingMetaObjects , fetchingMetaObjectsSet [metaID ])
213
+ }
214
+
210
215
// fetch LFS files from external server
211
216
err = lfsclient .FetchLFSFilesToContentStore (ctx , fetchingMetaObjects , userName , repo , LFSServer )
212
217
if err != nil {
@@ -217,7 +222,7 @@ func FetchLFSFilesToContentStore(ctx context.Context, repo *models.Repository, u
217
222
return nil
218
223
}
219
224
220
- func FindLFSMetaObjectsBelowMaxFileSize (commit * git.Commit , userName string , repo * models.Repository , fetchingMetaObjects * [ ]* models.LFSMetaObject ) error {
225
+ func FindLFSMetaObjectsBelowMaxFileSizeWithMissingFiles (commit * git.Commit , userName string , repo * models.Repository , fetchingMetaObjectsSet * map [ string ]* models.LFSMetaObject ) error {
221
226
entries , err := commit .Tree .ListEntriesRecursive ()
222
227
if err != nil {
223
228
log .Error ("Failed to access git commit %s tree: %v" , commit .ID .String (), err )
@@ -241,7 +246,7 @@ func FindLFSMetaObjectsBelowMaxFileSize(commit *git.Commit, userName string, rep
241
246
log .Error ("Unable to write LFS OID[%s] size %d meta object in %v/%v to database. Error: %v" , meta .Oid , meta .Size , userName , repo .Name , err )
242
247
return err
243
248
}
244
- * fetchingMetaObjects = append ( * fetchingMetaObjects , meta )
249
+ ( * fetchingMetaObjectsSet )[ meta . Oid ] = meta
245
250
}
246
251
return nil
247
252
}
0 commit comments