(
&self,
branch_name: &str,
repo: &mut Repository,
plan: ProspectiveImportPlan,
)
| 4843 | fields(branch = branch_name, commits = plan.commits.len()) |
| 4844 | )] |
| 4845 | pub(crate) fn import_prevalidated( |
| 4846 | &self, |
| 4847 | branch_name: &str, |
| 4848 | repo: &mut Repository, |
| 4849 | plan: ProspectiveImportPlan, |
| 4850 | ) -> CliResult<ImportStats> { |
| 4851 | let working_copy = repo |
| 4852 | .require_working_copy_id() |
| 4853 | .map_err(|e| CliError::Internal(e.into()))?; |
| 4854 | let mut stats = ImportStats { |
| 4855 | commits_found: plan.commits.len(), |
| 4856 | commits_parsed: plan.commits.len(), |
| 4857 | ..ImportStats::default() |
| 4858 | }; |
| 4859 | if plan.commits.is_empty() { |
| 4860 | let superseded = self.rewind_view_to_interpreted_tip(repo, branch_name)?; |
| 4861 | if superseded > 0 { |
| 4862 | print_info(&format!( |
| 4863 | "Superseded {superseded} change(s) no longer reachable from the Git tip of '{branch_name}'" |
| 4864 | )); |
| 4865 | } |
| 4866 | return Ok(stats); |
| 4867 | } |
| 4868 | |
| 4869 | let total = plan.commits.len(); |
| 4870 | print_info(&format!("Importing {total} preflight-verified commits...")); |
| 4871 | let import_start = Instant::now(); |
| 4872 | let mut line_index = ImportLineIndex::default(); |
| 4873 | let write_start = Instant::now(); |
| 4874 | // The import target tip for the supersede gate: the branch this walk |
| 4875 | // accumulates into the target view. A resolvable local branch names |
| 4876 | // its tip; a detached §7.5 import falls back to the walked commits. |
| 4877 | let target_tip = self.open_git_repo().ok().and_then(|git| { |
| 4878 | git.find_branch(branch_name, git2::BranchType::Local) |
| 4879 | .ok() |
| 4880 | .and_then(|branch| branch.get().target()) |
| 4881 | }); |
| 4882 | let (write_stats, all_imported_commits) = self.phase2_write( |
| 4883 | repo, |
| 4884 | &plan.commits, |
| 4885 | &mut line_index, |
| 4886 | plan.boundaries(), |
| 4887 | target_tip, |
| 4888 | )?; |
| 4889 | // CB-13C F4: a phase-2 failure is a FAILED partial import — the |
| 4890 | // landed commits are durable and accounted in the stats; the |
| 4891 | // caller surfaces the failure and the aggregate still emits. |
| 4892 | if let Some(failure) = &write_stats.failure { |
| 4893 | stats.changes_written = write_stats.changes_written; |
| 4894 | stats.empty_commits = write_stats.empty_commits; |
| 4895 | stats.merge_commits = write_stats.merge_commits; |
| 4896 | stats.resurrected_exact = write_stats.resurrected_exact; |
| 4897 | stats.files_processed = write_stats.files_processed; |
| 4898 | let landed = stats.changes_written + stats.empty_commits + stats.merge_commits; |
| 4899 | // CB-13C F4: the partial failure is accounted — the aggregate |
| 4900 | // emits with the landed count before the error propagates. |
| 4901 | emit_import_synthesis(repo, &stats, Some(landed)); |
| 4902 | return Err(CliError::Internal(anyhow::anyhow!( |
no test coverage detected