Fetch recent objects based on config
(fetchconf lfs.FetchPruneConfig, alreadyFetchedRefs []*git.Ref, filter *filepathfilter.Filter, watcher *fetchWatcher)
| 272 | |
| 273 | // Fetch recent objects based on config |
| 274 | func fetchRecent(fetchconf lfs.FetchPruneConfig, alreadyFetchedRefs []*git.Ref, filter *filepathfilter.Filter, watcher *fetchWatcher) bool { |
| 275 | if fetchconf.FetchRecentRefsDays == 0 && fetchconf.FetchRecentCommitsDays == 0 { |
| 276 | return true |
| 277 | } |
| 278 | |
| 279 | ok := true |
| 280 | // Make a list of what unique commits we've already fetched for to avoid duplicating work |
| 281 | uniqueRefShas := make(map[string]string, len(alreadyFetchedRefs)) |
| 282 | for _, ref := range alreadyFetchedRefs { |
| 283 | uniqueRefShas[ref.Sha] = ref.Name |
| 284 | } |
| 285 | // First find any other recent refs |
| 286 | if fetchconf.FetchRecentRefsDays > 0 { |
| 287 | printProgress(tr.Tr.GetN( |
| 288 | "Fetching recent branches within %v day", |
| 289 | "Fetching recent branches within %v days", |
| 290 | fetchconf.FetchRecentRefsDays, |
| 291 | fetchconf.FetchRecentRefsDays, |
| 292 | )) |
| 293 | refsSince := time.Now().AddDate(0, 0, -fetchconf.FetchRecentRefsDays) |
| 294 | refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, cfg.Remote()) |
| 295 | if err != nil { |
| 296 | Panic(err, tr.Tr.Get("Could not scan for recent refs")) |
| 297 | } |
| 298 | for _, ref := range refs { |
| 299 | // Don't fetch for the same SHA twice |
| 300 | if prevRefName, ok := uniqueRefShas[ref.Sha]; ok { |
| 301 | if ref.Name != prevRefName { |
| 302 | tracerx.Printf("Skipping fetch for %v, already fetched via %v", ref.Name, prevRefName) |
| 303 | } |
| 304 | } else { |
| 305 | uniqueRefShas[ref.Sha] = ref.Name |
| 306 | printProgress(tr.Tr.Get("Fetching reference %s", ref.Name)) |
| 307 | k := fetchRef(ref.Sha, filter, watcher) |
| 308 | ok = ok && k |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | // For every unique commit we've fetched, check recent commits too |
| 313 | if fetchconf.FetchRecentCommitsDays > 0 { |
| 314 | for commit, refName := range uniqueRefShas { |
| 315 | // We measure from the last commit at the ref |
| 316 | summ, err := git.GetCommitSummary(commit) |
| 317 | if err != nil { |
| 318 | Error(tr.Tr.Get("Couldn't scan commits at %v: %v", refName, err)) |
| 319 | continue |
| 320 | } |
| 321 | printProgress(tr.Tr.GetN( |
| 322 | "Fetching changes within %v day of %v", |
| 323 | "Fetching changes within %v days of %v", |
| 324 | fetchconf.FetchRecentCommitsDays, |
| 325 | fetchconf.FetchRecentCommitsDays, |
| 326 | refName, |
| 327 | )) |
| 328 | commitsSince := summ.CommitDate.AddDate(0, 0, -fetchconf.FetchRecentCommitsDays) |
| 329 | k := fetchPreviousVersions(commit, commitsSince, filter, watcher) |
| 330 | ok = ok && k |
| 331 | } |
no test coverage detected