Open the service session for an explicit repository path (the Reactor's typed dispatch always passes the canonical root).
(root: &Path)
| 147 | /// Open the service session for an explicit repository path (the |
| 148 | /// Reactor's typed dispatch always passes the canonical root). |
| 149 | pub fn open_root(root: &Path) -> CliResult<Option<Service>> { |
| 150 | // A remote sandbox holds no repository the service could resolve — |
| 151 | // only a pointer and its cache. Its commands run their local bodies |
| 152 | // over the cache, which reaches the serving host through the |
| 153 | // sandbox link (see `crate::remote_sandbox`). |
| 154 | if atomic_repository::find_remote_sandbox(root).is_some() { |
| 155 | return Ok(None); |
| 156 | } |
| 157 | let mode = mode(); |
| 158 | let rt = tokio::runtime::Builder::new_current_thread() |
| 159 | .enable_all() |
| 160 | .build() |
| 161 | .map_err(|error| CliError::Internal(anyhow::anyhow!("service runtime: {error}")))?; |
| 162 | match mode { |
| 163 | Mode::Local => { |
| 164 | // In-process: construct the handler state and resolve the |
| 165 | // repository through the SAME handler the transport serves. |
| 166 | // No socket, no daemon, no client — ever. |
| 167 | let state = Arc::new(DaemonState::new()); |
| 168 | let daemon = services::DaemonImpl { |
| 169 | state: state.clone(), |
| 170 | }; |
| 171 | let resolved = rt |
| 172 | .block_on(daemon.resolve_repository(Request::new( |
| 173 | pb::ResolveRepositoryRequest { |
| 174 | path: root.display().to_string(), |
| 175 | }, |
| 176 | ))) |
| 177 | .map_err(|error| { |
| 178 | CliError::Internal(anyhow::anyhow!("local service resolve failed: {error}")) |
| 179 | })? |
| 180 | .into_inner(); |
| 181 | let reference = resolved.repository.ok_or_else(|| { |
| 182 | CliError::Internal(anyhow::anyhow!("local service resolved no repository")) |
| 183 | })?; |
| 184 | Ok(Some(Service { |
| 185 | mode, |
| 186 | reference, |
| 187 | local: Some(state), |
| 188 | reactor: None, |
| 189 | rt, |
| 190 | })) |
| 191 | } |
| 192 | Mode::Reactor => { |
| 193 | // D4 start-or-retry: connect, starting the transport when |
| 194 | // it is down, then resolve the repository over the socket. |
| 195 | // Strict — there is no auto fallback. |
| 196 | let connect = async { |
| 197 | let client = atomic_client::AtomicClient::connect_or_start() |
| 198 | .await |
| 199 | .map_err(|e| anyhow::anyhow!(e))?; |
| 200 | let mut daemon = |
| 201 | pb::daemon_service_client::DaemonServiceClient::new(client.channel.clone()); |
| 202 | let resolved = daemon |
| 203 | .resolve_repository(pb::ResolveRepositoryRequest { |
| 204 | path: root.display().to_string(), |
| 205 | }) |
| 206 | .await? |
nothing calls this directly
no test coverage detected