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