git-bug 0.2.4

A rust library for interfacing with git-bug repositories
Documentation
// git-bug-rs - A rust library for interfacing with git-bug repositories
//
// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of git-bug-rs/git-gub.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/agpl.txt>.

//! Handling of the actual issues.
//!
//! # Note
//! Git-bug calls these `Bugs`.
//! See the documentation at the crate root for an explanation on this name
//! difference.

use serde::{Deserialize, Serialize};

use self::{
    issue_operation::IssueOperationData,
    snapshot::{history_step::IssueHistoryStep, timeline::IssueTimeline},
};
use crate::replica::entity::{self, Entity, EntityRead, operation::operations::Operations};

pub mod data;
pub mod issue_operation;
pub mod query;
pub mod snapshot;

/// The representation of an issue in it's DAG form.
/// This means that this issue can be modified (i.e., operations added) and than
/// re-commited to disk.
#[derive(Debug, Serialize, Deserialize)]
pub struct Issue {
    operations: Operations<Self>,
    create_time: entity::lamport::Time,
    edit_time: entity::lamport::Time,
    current_head: gix::ObjectId,
}

impl Entity for Issue {
    type HistoryStep = IssueHistoryStep;
    type OperationData = IssueOperationData;
    type Timeline = IssueTimeline;

    const FORMAT_VERSION: usize = 4;
    const NAMESPACE: &str = "bugs";
    const TYPENAME: &str = "Issue";

    fn operations(&self) -> &Operations<Self>
    where
        Self: Sized,
    {
        &self.operations
    }

    unsafe fn from_parts(
        operations: Operations<Self>,
        create_time: entity::lamport::Time,
        edit_time: entity::lamport::Time,
        current_head: gix::ObjectId,
    ) -> Self {
        Self {
            operations,
            create_time,
            edit_time,
            current_head,
        }
    }

    fn create_time(&self) -> &entity::lamport::Time
    where
        Self: Sized,
    {
        &self.create_time
    }

    fn edit_time(&self) -> &entity::lamport::Time
    where
        Self: Sized,
    {
        &self.edit_time
    }

    fn current_head(&self) -> &gix::oid
    where
        Self: Sized,
    {
        &self.current_head
    }
}

impl EntityRead for Issue {
    // TODO(@bpeetz): Ideally, this would be the default. But alas, defaults for
    // associated types are not yet stable. <2025-04-21>
    type CustomReadError = std::convert::Infallible;
}