pub struct GitRepository { /* private fields */ }Expand description
Git repository wrapper that handles Send/Sync constraints
git2::Repository is not Send/Sync due to internal raw pointers. We work around this by storing the path and using spawn_blocking for all git operations.
Implementations§
Source§impl GitRepository
impl GitRepository
Sourcepub fn discover<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn discover<P: AsRef<Path>>(path: P) -> Result<Self>
Discover a repository starting from the given path
Sourcepub fn workdir(&self) -> &Path
pub fn workdir(&self) -> &Path
Get the working directory root (parent of .git directory).
If path ends with .git, returns its parent. Otherwise returns path as-is.
This is the directory that contains the actual source files.
Sourcepub async fn ensure_depth(&self, depth: u32) -> Result<()>
pub async fn ensure_depth(&self, depth: u32) -> Result<()>
Ensure repository has sufficient depth for diff
Sourcepub async fn ensure_depth_with_retry(
&self,
base_sha: &str,
head_sha: &str,
initial_depth: u32,
max_retries: u32,
) -> Result<()>
pub async fn ensure_depth_with_retry( &self, base_sha: &str, head_sha: &str, initial_depth: u32, max_retries: u32, ) -> Result<()>
Ensure repository has sufficient depth with retry and exponential deepening
Tries to find the merge base between base and head. If the merge base is not reachable (shallow clone), deepens the repository and retries.
Sourcepub fn is_symlink_in_tree(&self, sha: &str, file_path: &str) -> Result<bool>
pub fn is_symlink_in_tree(&self, sha: &str, file_path: &str) -> Result<bool>
Check if a path is a symlink in a specific tree (by SHA)
Useful for detecting symlinks in deleted files where the working tree no longer has the file. Falls back to checking the git tree object.
Sourcepub fn diff_sync(
&self,
base_sha: &str,
head_sha: &str,
interner: &StringInterner,
diff_filter: &str,
) -> Result<DiffResult>
pub fn diff_sync( &self, base_sha: &str, head_sha: &str, interner: &StringInterner, diff_filter: &str, ) -> Result<DiffResult>
Compute diff between two commits (sync version)
Sourcepub fn resolve_sha_sync(&self, reference: &str) -> Result<String>
pub fn resolve_sha_sync(&self, reference: &str) -> Result<String>
Resolve a reference to a SHA (sync version)
Sourcepub fn submodules_sync(&self) -> Result<Vec<String>>
pub fn submodules_sync(&self) -> Result<Vec<String>>
Get list of submodule paths (sync version)
Source§impl GitRepository
impl GitRepository
Sourcepub async fn diff(
&self,
base_sha: &str,
head_sha: &str,
interner: &StringInterner,
diff_filter: &str,
) -> Result<DiffResult>
pub async fn diff( &self, base_sha: &str, head_sha: &str, interner: &StringInterner, diff_filter: &str, ) -> Result<DiffResult>
Compute the diff between two SHAs, interning paths as they stream out.
The git2 work runs inline on the calling task: the endpoint tree diff is CPU/page-cache bound and completes in single-digit milliseconds on real repositories, so a spawn_blocking hop would cost more than it saves.
Trait Implementations§
impl Send for GitRepository
impl Sync for GitRepository
Auto Trait Implementations§
impl Freeze for GitRepository
impl RefUnwindSafe for GitRepository
impl Unpin for GitRepository
impl UnsafeUnpin for GitRepository
impl UnwindSafe for GitRepository
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more