MCPcopy
hub / github.com/git-lfs/git-lfs / prune

Function prune

commands/command_prune.go:81–229  ·  view source on GitHub ↗
(fetchPruneConfig lfs.FetchPruneConfig, verifyRemote, verifyUnreachable, continueWhenUnverified, dryRun, verbose bool)

Source from the content-addressed store, hash-verified

79type PruneProgressChan chan PruneProgress
80
81func prune(fetchPruneConfig lfs.FetchPruneConfig, verifyRemote, verifyUnreachable, continueWhenUnverified, dryRun, verbose bool) {
82 localObjects := make([]fs.Object, 0, 100)
83 retainedObjects := tools.NewStringSetWithCapacity(100)
84
85 logger := tasklog.NewLogger(OutputWriter,
86 tasklog.ForceProgress(cfg.ForceProgress()),
87 )
88 defer logger.Close()
89
90 var reachableObjects tools.StringSet
91 var taskwait sync.WaitGroup
92
93 // Add all the base funcs to the waitgroup before starting them, in case
94 // one completes really fast & hits 0 unexpectedly
95 // each main process can Add() to the wg itself if it subdivides the task
96 taskwait.Add(5) // 1..5: localObjects, current & recent refs, unpushed, worktree, stashes
97 if verifyRemote && !verifyUnreachable {
98 taskwait.Add(1) // 6
99 }
100
101 progressChan := make(PruneProgressChan, 100)
102
103 // Collect errors
104 errorChan := make(chan error, 10)
105 var errorwait sync.WaitGroup
106 errorwait.Add(1)
107 var taskErrors []error
108 go pruneTaskCollectErrors(&taskErrors, errorChan, &errorwait)
109
110 // Populate the single list of local objects
111 go pruneTaskGetLocalObjects(&localObjects, progressChan, &taskwait)
112
113 // Now find files to be retained from many sources
114 retainChan := make(chan string, 100)
115
116 gitscanner := lfs.NewGitScanner(cfg, nil)
117 gitscanner.Filter = filepathfilter.New(nil, cfg.FetchExcludePaths(), filepathfilter.GitIgnore)
118
119 sem := semaphore.NewWeighted(int64(runtime.NumCPU() * 2))
120
121 go pruneTaskGetRetainedCurrentAndRecentRefs(gitscanner, fetchPruneConfig, retainChan, errorChan, &taskwait, sem)
122 go pruneTaskGetRetainedUnpushed(gitscanner, fetchPruneConfig, retainChan, errorChan, &taskwait, sem)
123 go pruneTaskGetRetainedWorktree(gitscanner, fetchPruneConfig, retainChan, errorChan, &taskwait, sem)
124 go pruneTaskGetRetainedStashed(gitscanner, retainChan, errorChan, &taskwait, sem)
125 if verifyRemote && !verifyUnreachable {
126 reachableObjects = tools.NewStringSetWithCapacity(100)
127 go pruneTaskGetReachableObjects(gitscanner, &reachableObjects, errorChan, &taskwait, sem)
128 }
129
130 // Now collect all the retained objects, on separate wait
131 var retainwait sync.WaitGroup
132 retainwait.Add(1)
133 go pruneTaskCollectRetained(&retainedObjects, retainChan, progressChan, &retainwait)
134
135 // Report progress
136 var progresswait sync.WaitGroup
137 progresswait.Add(1)
138 go pruneTaskDisplayProgress(progressChan, &progresswait, logger)

Callers 3

pruneCommandFunction · 0.85
fetchCommandFunction · 0.85
migrateExportCommandFunction · 0.85

Calls 15

CloseMethod · 0.95
WatchMethod · 0.95
AddMethod · 0.95
AddMethod · 0.95
WaitMethod · 0.95
NewStringSetWithCapacityFunction · 0.92
NewLoggerFunction · 0.92
ForceProgressFunction · 0.92
NewGitScannerFunction · 0.92
NewFunction · 0.92
FormatBytesFunction · 0.92
NewPointerFunction · 0.92

Tested by

no test coverage detected