The handler body, shared with the trait impl in `services.rs`.
(
state: &Arc<DaemonState>,
request: Request<DiffWorkingCopyRequest>,
)
| 21 | |
| 22 | /// The handler body, shared with the trait impl in `services.rs`. |
| 23 | pub async fn diff_working_copy_impl( |
| 24 | state: &Arc<DaemonState>, |
| 25 | request: Request<DiffWorkingCopyRequest>, |
| 26 | ) -> Result<Response<<super::services::QueryImpl as repository_query_service_server::RepositoryQueryService>::DiffWorkingCopyStream>, Status>{ |
| 27 | let request = request.into_inner(); |
| 28 | let handle = state.resolve(request.repository.as_ref().unwrap())?; |
| 29 | state.log_rpc("DiffWorkingCopy", Some(&handle)); |
| 30 | let scope = request.working_copy.unwrap_or_default(); |
| 31 | let stat_only = request.stat_only; |
| 32 | let paths = scope.paths; |
| 33 | |
| 34 | let (sender, receiver) = tokio::sync::mpsc::channel::<Result<DiffChunk, Status>>(16); |
| 35 | let handle_for_task = handle; |
| 36 | tokio::spawn(async move { |
| 37 | let gate_handle = handle_for_task.clone(); |
| 38 | let _gate = gate_handle.exclusive().await; |
| 39 | let result = tokio::task::spawn_blocking(move || { |
| 40 | compute_working_copy_diff(&handle_for_task, &paths, scope.include_untracked, stat_only) |
| 41 | }) |
| 42 | .await |
| 43 | .unwrap_or_else(|error| Err(Status::internal(error.to_string()))); |
| 44 | match result { |
| 45 | Ok(chunks) => { |
| 46 | for chunk in chunks { |
| 47 | if sender.send(Ok(chunk)).await.is_err() { |
| 48 | break; // client went away |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | Err(error) => { |
| 53 | let _ = sender.send(Err(error)).await; |
| 54 | } |
| 55 | } |
| 56 | }); |
| 57 | Ok(Response::new(Box::pin( |
| 58 | tokio_stream::wrappers::ReceiverStream::new(receiver), |
| 59 | ))) |
| 60 | } |
| 61 | |
| 62 | /// Compute the working-copy diff chunks: recorded graph content (via |
| 63 | /// `get_file_content_on_view`) against the on-disk bytes, unified-diffed |
no test coverage detected