MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / phase1_parse

Method phase1_parse

atomic-cli/src/commands/git/parallel.rs:5202–5263  ·  view source on GitHub ↗
(&self, commit_oids: &[Oid])

Source from the content-addressed store, hash-verified

5200 /// Phase 1: Parse all commits in parallel using rayon.
5201 #[tracing::instrument(name = "parse", skip_all, fields(commits = commit_oids.len()))]
5202 fn phase1_parse(&self, commit_oids: &[Oid]) -> CliResult<Vec<ParsedCommit>> {
5203 // Build a map from OID to index for parent lookups
5204 let oid_to_index: std::collections::HashMap<Oid, usize> = commit_oids
5205 .iter()
5206 .enumerate()
5207 .map(|(i, oid)| (*oid, i))
5208 .collect();
5209
5210 // Progress counter for large repos
5211 let progress = Arc::new(AtomicUsize::new(0));
5212 let total = commit_oids.len();
5213
5214 // Share the repo path for thread-local repo opening
5215 let repo_path = self.git_repo_path.clone();
5216 // Rayon's threads don't inherit the span; log their lines inside it.
5217 let parse_span = tracing::Span::current();
5218
5219 // Parse commits in parallel - each thread opens its own git repo
5220 let results: Vec<CliResult<ParsedCommit>> = commit_oids
5221 .par_iter()
5222 .enumerate()
5223 .map(|(idx, oid)| {
5224 let _span = parse_span.enter();
5225 // Progress reporting (every 100 commits)
5226 let count = progress.fetch_add(1, Ordering::Relaxed);
5227 if total > 100 && count.is_multiple_of(100) {
5228 print_info(&format!(" Parsed {}/{} commits...", count, total));
5229 }
5230
5231 // Open a thread-local git repo
5232 let git_repo = GitRepository::open(&repo_path).map_err(|e| CliError::GitError {
5233 message: format!("Failed to open git repository: {}", e),
5234 })?;
5235
5236 let parsed = parse_commit(&git_repo, *oid, idx, &oid_to_index)?;
5237 Ok(parsed)
5238 })
5239 .collect();
5240
5241 // Collect results, filtering out errors (with warnings)
5242 let mut parsed = Vec::with_capacity(results.len());
5243 for (idx, result) in results.into_iter().enumerate() {
5244 match result {
5245 Ok(commit) => parsed.push(commit),
5246 Err(e) => {
5247 tracing::info!(target: GIT_IMPORT_LOG_TARGET, idx, error = %e, "parse failed; commit skipped");
5248 print_warning(&format!("Skipping commit {}: {}", idx, e));
5249 }
5250 }
5251 }
5252
5253 // Sort by original index to restore topological order
5254 // (rayon may have processed them out of order)
5255 parsed.sort_by_key(|c| {
5256 commit_oids
5257 .iter()
5258 .position(|oid| oid.to_string() == c.git_sha)
5259 .unwrap_or(usize::MAX)

Calls 13

print_infoFunction · 0.85
openFunction · 0.85
parse_commitFunction · 0.85
print_warningFunction · 0.85
currentFunction · 0.70
collectMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
enterMethod · 0.45
into_iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected