MCPcopy Index your code
hub / github.com/git-lfs/git-lfs / pruneTaskGetRetainedCurrentAndRecentRefs

Function pruneTaskGetRetainedCurrentAndRecentRefs

commands/command_prune.go:431–484  ·  view source on GitHub ↗

Background task, must call waitg.Done() once at end

(gitscanner *lfs.GitScanner, fetchconf lfs.FetchPruneConfig, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup, sem *semaphore.Weighted)

Source from the content-addressed store, hash-verified

429
430// Background task, must call waitg.Done() once at end
431func pruneTaskGetRetainedCurrentAndRecentRefs(gitscanner *lfs.GitScanner, fetchconf lfs.FetchPruneConfig, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup, sem *semaphore.Weighted) {
432 defer waitg.Done()
433
434 // We actually increment the waitg in this func since we kick off sub-goroutines
435 // Make a list of what unique commits to keep, & search backward from
436 commits := tools.NewStringSet()
437 // Do current first
438 ref, err := git.CurrentRef()
439 if err != nil {
440 errorChan <- err
441 return
442 }
443 commits.Add(ref.Sha)
444 if !fetchconf.PruneForce {
445 waitg.Add(1)
446 go pruneTaskGetRetainedAtRef(gitscanner, ref.Sha, retainChan, errorChan, waitg, sem)
447 }
448
449 // Now recent
450 if !fetchconf.PruneRecent && fetchconf.FetchRecentRefsDays > 0 {
451 pruneRefDays := fetchconf.FetchRecentRefsDays + fetchconf.PruneOffsetDays
452 tracerx.Printf("PRUNE: Retaining non-HEAD refs within %d (%d+%d) days", pruneRefDays, fetchconf.FetchRecentRefsDays, fetchconf.PruneOffsetDays)
453 refsSince := time.Now().AddDate(0, 0, -pruneRefDays)
454 // Keep all recent refs including any recent remote branches
455 refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, "")
456 if err != nil {
457 Panic(err, tr.Tr.Get("Could not scan for recent refs"))
458 }
459 for _, ref := range refs {
460 if commits.Add(ref.Sha) {
461 // A new commit
462 waitg.Add(1)
463 go pruneTaskGetRetainedAtRef(gitscanner, ref.Sha, retainChan, errorChan, waitg, sem)
464 }
465 }
466 }
467
468 // For every unique commit we've fetched, check recent commits too
469 // Only if we're fetching recent commits, otherwise only keep at refs
470 if !fetchconf.PruneRecent && fetchconf.FetchRecentCommitsDays > 0 {
471 pruneCommitDays := fetchconf.FetchRecentCommitsDays + fetchconf.PruneOffsetDays
472 for commit := range commits.Iter() {
473 // We measure from the last commit at the ref
474 summ, err := git.GetCommitSummary(commit)
475 if err != nil {
476 errorChan <- errors.New(tr.Tr.Get("couldn't scan commits at %v: %v", commit, err))
477 continue
478 }
479 commitsSince := summ.CommitDate.AddDate(0, 0, -pruneCommitDays)
480 waitg.Add(1)
481 go pruneTaskGetPreviousVersionsOfRef(gitscanner, commit, commitsSince, retainChan, errorChan, waitg, sem)
482 }
483 }
484}
485
486// Background task, must call waitg.Done() once at end
487func pruneTaskGetRetainedUnpushed(gitscanner *lfs.GitScanner, fetchconf lfs.FetchPruneConfig, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup, sem *semaphore.Weighted) {

Callers 1

pruneFunction · 0.85

Calls 13

AddMethod · 0.95
IterMethod · 0.95
NewStringSetFunction · 0.92
CurrentRefFunction · 0.92
RecentBranchesFunction · 0.92
GetCommitSummaryFunction · 0.92
NewFunction · 0.92
PanicFunction · 0.85
AddMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected