Skip to main content

hyprstream_p2p/git/
mod.rs

1//! Git protocol utilities for SHA256 object operations
2
3pub mod objects;
4pub mod protocol;
5pub mod remote;
6pub mod remote_helper;
7pub mod repository;
8pub mod transport;
9
10pub use objects::*;
11pub use protocol::*;
12pub use remote::*;
13pub use repository::Repository;
14pub use transport::{register_gittorrent_transport, GittorrentTransportFactory};
15
16use crate::Result;
17use std::path::PathBuf;
18
19/// Execute a blocking git2 operation on a repository opened from the given path.
20///
21/// `git2::Repository` is `!Send`, so we pass an owned `PathBuf`, open a fresh
22/// repository inside `spawn_blocking`, and return owned results.
23pub(crate) async fn with_repo_blocking<F, T>(path: PathBuf, f: F) -> Result<T>
24where
25    F: FnOnce(git2::Repository) -> Result<T> + Send + 'static,
26    T: Send + 'static,
27{
28    tokio::task::spawn_blocking(move || {
29        let repo = git2::Repository::open(&path)?;
30        f(repo)
31    })
32    .await
33    .map_err(|e| crate::Error::other(format!("Task join error: {e}")))?
34}