mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-20 16:11:46 +03:00
27 lines
738 B
Rust
27 lines
738 B
Rust
use bstr::BStr;
|
|
|
|
use crate::commit_headers::HasCommitHeaders;
|
|
|
|
/// Extension trait for `git2::Commit`.
|
|
///
|
|
/// For now, it collects useful methods from `gitbutler-core::git::Commit`
|
|
pub trait CommitExt {
|
|
/// Obtain the commit-message as bytes, but without assuming any encoding.
|
|
fn message_bstr(&self) -> &BStr;
|
|
fn change_id(&self) -> Option<String>;
|
|
fn is_signed(&self) -> bool;
|
|
}
|
|
|
|
impl<'repo> CommitExt for git2::Commit<'repo> {
|
|
fn message_bstr(&self) -> &BStr {
|
|
self.message_bytes().as_ref()
|
|
}
|
|
|
|
fn change_id(&self) -> Option<String> {
|
|
self.gitbutler_headers().map(|headers| headers.change_id)
|
|
}
|
|
fn is_signed(&self) -> bool {
|
|
self.header_field_bytes("gpgsig").is_ok()
|
|
}
|
|
}
|