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

Method import_branch

atomic-cli/src/commands/git/parallel.rs:2262–2509  ·  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

2260 /// Imports use a fixed 1,000-commit batch size. This keeps progress and
2261 /// memory behavior predictable across small and large repositories.
2262 pub fn import_branch(
2263 &self,
2264 branch_name: &str,
2265 repo: &mut Repository,
2266 ) -> CliResult<ImportStats> {
2267 let mut stats = ImportStats::default();
2268
2269 // Open git repo for this thread
2270 let git_repo = self.open_git_repo()?;
2271
2272 // Collect commit OIDs in topological order
2273 let commit_oids = self.collect_commit_oids(&git_repo, branch_name)?;
2274 stats.commits_found = commit_oids.len();
2275
2276 if commit_oids.is_empty() {
2277 return Ok(stats);
2278 }
2279
2280 let total = commit_oids.len();
2281 let batch_size = Self::batch_size_for(total);
2282
2283 print_info(&format!(
2284 "Importing {} commits in batches of {}...",
2285 total, batch_size
2286 ));
2287
2288 let import_start = Instant::now();
2289 let mut commits_written = 0usize;
2290 let mut line_index = ImportLineIndex::default();
2291 let mut all_imported_commits: Vec<ImportedCommitInfo> = Vec::new();
2292
2293 for (batch_idx, chunk) in commit_oids.chunks(batch_size).enumerate() {
2294 let batch_start = batch_idx * batch_size;
2295 let batch_end = (batch_start + chunk.len()).min(total);
2296
2297 print_info(&format!(
2298 "Batch {}: parsing commits {}-{} of {}...",
2299 batch_idx + 1,
2300 batch_start,
2301 batch_end,
2302 total
2303 ));
2304
2305 // Phase 1: Parallel git parsing for this batch
2306 let parse_start = Instant::now();
2307 let parsed_commits = self.phase1_parse(chunk)?;
2308 let parse_elapsed = parse_start.elapsed();
2309
2310 stats.phase1_duration += parse_elapsed;
2311 stats.commits_parsed += parsed_commits.len();
2312
2313 if parsed_commits.is_empty() {
2314 continue;
2315 }
2316
2317 // Phase 2: Sequential write for this batch
2318 let write_start = Instant::now();
2319 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