Skip to main content

grit_protocol/
session.rs

1//! Per-request session controls for smart-protocol handlers.
2
3use std::sync::Arc;
4
5use grit_lib::progress::CancelToken;
6use grit_lib::remote::serve::ReceiveHook;
7
8/// Hooks and cancellation for one upload-pack or receive-pack exchange.
9#[derive(Clone, Default)]
10pub struct ServeSession {
11    /// In-process receive-pack checks alongside [`crate::PushGuard`].
12    pub receive_hook: Option<Arc<dyn ReceiveHook + Send + Sync>>,
13    /// When set, long-running serve work stops without moving refs on push.
14    pub cancel: Option<Arc<grit_lib::progress::CancelToken>>,
15}
16
17impl ServeSession {
18    /// No extra hook and no cancel signal.
19    #[must_use]
20    pub fn none() -> Self {
21        Self::default()
22    }
23
24    pub(crate) fn cancel(&self) -> &CancelToken {
25        if let Some(c) = self.cancel.as_deref() {
26            c
27        } else {
28            CancelToken::never_ref()
29        }
30    }
31}
32
33/// Buffered receive-pack response plus the typed session outcome.
34#[derive(Debug)]
35pub struct ReceiveRpcResult {
36    /// The HTTP or smart-HTTP response body (report-status).
37    pub body: Vec<u8>,
38    /// What the push stored and which updates were applied.
39    pub outcome: grit_lib::remote::serve::ReceiveOutcome,
40}