Experimental direct graph-only import. No fallback to working-copy recording; caller controls the optional final checkout after success.
(
&self,
repo: &mut Repository,
tip: Oid,
limits: GitStreamLimits,
)
| 893 | /// Experimental direct graph-only import. No fallback to working-copy |
| 894 | /// recording; caller controls the optional final checkout after success. |
| 895 | pub(crate) fn import_graph_stream( |
| 896 | &self, |
| 897 | repo: &mut Repository, |
| 898 | tip: Oid, |
| 899 | limits: GitStreamLimits, |
| 900 | ) -> CliResult<GitStreamOutcome> { |
| 901 | #[cfg(test)] |
| 902 | let _recorder_guard = RecorderGuard::new(); |
| 903 | if !self.options.graph_only |
| 904 | || !self.options.mainline_only |
| 905 | || self.options.incremental |
| 906 | || !self.options.imported_shas.is_empty() |
| 907 | || self.options.target_view != repo.current_view() |
| 908 | { |
| 909 | return Err(git_error("direct stream initially requires graph-only fresh first-parent import into the current empty view; eager CRDT/incremental/all-parent modes are unsupported")); |
| 910 | } |
| 911 | let (git, policy, ordered) = self.graph_stream_inputs(tip)?; |
| 912 | let positions: HashMap<_, _> = ordered |
| 913 | .iter() |
| 914 | .copied() |
| 915 | .enumerate() |
| 916 | .map(|(index, oid)| (oid, index)) |
| 917 | .collect(); |
| 918 | let mut session = if self.options.span_stream { |
| 919 | GitGraphImportSession::begin_span(repo, limits) |
| 920 | } else { |
| 921 | GitGraphImportSession::begin(repo, limits) |
| 922 | } |
| 923 | .map_err(CliError::from)?; |
| 924 | let mut compiler = Compiler::default(); |
| 925 | if self.options.span_stream { |
| 926 | compiler.spans = Some(Default::default()); |
| 927 | } |
| 928 | let mut batch = Vec::new(); |
| 929 | let mut bytes = 0usize; |
| 930 | let mut staged = 0usize; |
| 931 | let started = Instant::now(); |
| 932 | for (index, oid) in ordered.iter().copied().enumerate() { |
| 933 | let commit = git.find_commit(oid).map_err(|e| git_error(e.to_string()))?; |
| 934 | input_budget(&git, &commit, limits.bytes())?; |
| 935 | let parsed = parse_commit_with_scope(&git, oid, index, &positions, false)?; |
| 936 | let metadata = self.build_git_metadata(&parsed, parsed.is_empty, parsed.is_merge); |
| 937 | let prepared = compiler.compile(&parsed, &policy, &[], metadata)?; |
| 938 | if prepared.payload_bytes() > limits.bytes() { |
| 939 | return Err(git_error( |
| 940 | "single compiled stream change exceeds byte bound", |
| 941 | )); |
| 942 | } |
| 943 | if !batch.is_empty() |
| 944 | && (batch.len() == limits.commits() |
| 945 | || bytes + prepared.payload_bytes() > limits.bytes()) |
| 946 | { |
| 947 | session.publish(&batch).map_err(CliError::from)?; |
| 948 | staged += batch.len(); |
| 949 | print_info(&format!( |
| 950 | "Direct stream staged {staged}/{} commits privately ({:.2}s)", |
| 951 | ordered.len(), |
| 952 | started.elapsed().as_secs_f64() |