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

Method import_branch

atomic-cli/src/commands/git/parallel.rs:2218–2461  ·  view source on GitHub ↗

Import commits from a branch into an Atomic repository. Commits are processed in **batches** to keep memory bounded and show progress sooner. Each batch: parse in parallel → write sequentially. Imports use a fixed 1,000-commit batch size. This keeps progress and memory behavior predictable across small and large repositories.

(
        &self,
        branch_name: &str,
        repo: &mut Repository,
    )

Source from the content-addressed store, hash-verified

2216 /// Imports use a fixed 1,000-commit batch size. This keeps progress and
2217 /// memory behavior predictable across small and large repositories.
2218 pub fn import_branch(
2219 &self,
2220 branch_name: &str,
2221 repo: &mut Repository,
2222 ) -> CliResult<ImportStats> {
2223 let mut stats = ImportStats::default();
2224
2225 // Open git repo for this thread
2226 let git_repo = self.open_git_repo()?;
2227
2228 // Collect commit OIDs in topological order
2229 let commit_oids = self.collect_commit_oids(&git_repo, branch_name)?;
2230 stats.commits_found = commit_oids.len();
2231
2232 if commit_oids.is_empty() {
2233 return Ok(stats);
2234 }
2235
2236 let total = commit_oids.len();
2237 let batch_size = Self::batch_size_for(total);
2238
2239 print_info(&format!(
2240 "Importing {} commits in batches of {}...",
2241 total, batch_size
2242 ));
2243
2244 let import_start = Instant::now();
2245 let mut commits_written = 0usize;
2246 let mut line_index = ImportLineIndex::default();
2247 let mut all_imported_commits: Vec<ImportedCommitInfo> = Vec::new();
2248
2249 for (batch_idx, chunk) in commit_oids.chunks(batch_size).enumerate() {
2250 let batch_start = batch_idx * batch_size;
2251 let batch_end = (batch_start + chunk.len()).min(total);
2252
2253 print_info(&format!(
2254 "Batch {}: parsing commits {}-{} of {}...",
2255 batch_idx + 1,
2256 batch_start,
2257 batch_end,
2258 total
2259 ));
2260
2261 // Phase 1: Parallel git parsing for this batch
2262 let parse_start = Instant::now();
2263 let parsed_commits = self.phase1_parse(chunk)?;
2264 let parse_elapsed = parse_start.elapsed();
2265
2266 stats.phase1_duration += parse_elapsed;
2267 stats.commits_parsed += parsed_commits.len();
2268
2269 if parsed_commits.is_empty() {
2270 continue;
2271 }
2272
2273 // Phase 2: Sequential write for this batch
2274 let write_start = Instant::now();
2275 let (write_stats, batch_imported) =

Callers

nothing calls this directly

Calls 15

print_infoFunction · 0.85
print_warningFunction · 0.85
open_git_repoMethod · 0.80
collect_commit_oidsMethod · 0.80
phase1_parseMethod · 0.80
phase2_writeMethod · 0.80
extendMethod · 0.80
list_tracked_filesMethod · 0.80
phase3_finalizeMethod · 0.80
untrackedMethod · 0.80

Tested by

no test coverage detected