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

Method import_branch

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

2147 /// Imports use a fixed 1,000-commit batch size. This keeps progress and
2148 /// memory behavior predictable across small and large repositories.
2149 pub fn import_branch(
2150 &self,
2151 branch_name: &str,
2152 repo: &mut Repository,
2153 ) -> CliResult<ImportStats> {
2154 let mut stats = ImportStats::default();
2155
2156 // Open git repo for this thread
2157 let git_repo = self.open_git_repo()?;
2158
2159 // Collect commit OIDs in topological order
2160 let commit_oids = self.collect_commit_oids(&git_repo, branch_name)?;
2161 stats.commits_found = commit_oids.len();
2162
2163 if commit_oids.is_empty() {
2164 return Ok(stats);
2165 }
2166
2167 let total = commit_oids.len();
2168 let batch_size = Self::batch_size_for(total);
2169
2170 print_info(&format!(
2171 "Importing {} commits in batches of {}...",
2172 total, batch_size
2173 ));
2174
2175 let import_start = Instant::now();
2176 let mut commits_written = 0usize;
2177 let mut line_index = ImportLineIndex::default();
2178 let mut all_imported_commits: Vec<ImportedCommitInfo> = Vec::new();
2179
2180 for (batch_idx, chunk) in commit_oids.chunks(batch_size).enumerate() {
2181 let batch_start = batch_idx * batch_size;
2182 let batch_end = (batch_start + chunk.len()).min(total);
2183
2184 print_info(&format!(
2185 "Batch {}: parsing commits {}-{} of {}...",
2186 batch_idx + 1,
2187 batch_start,
2188 batch_end,
2189 total
2190 ));
2191
2192 // Phase 1: Parallel git parsing for this batch
2193 let parse_start = Instant::now();
2194 let parsed_commits = self.phase1_parse(chunk)?;
2195 let parse_elapsed = parse_start.elapsed();
2196
2197 stats.phase1_duration += parse_elapsed;
2198 stats.commits_parsed += parsed_commits.len();
2199
2200 if parsed_commits.is_empty() {
2201 continue;
2202 }
2203
2204 // Phase 2: Sequential write for this batch
2205 let write_start = Instant::now();
2206 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
untrackedMethod · 0.80
phase3_finalizeMethod · 0.80

Tested by

no test coverage detected