gix_merge/blob/platform/
resource.rs

1use crate::blob::{
2    pipeline,
3    platform::{Resource, ResourceRef},
4};
5
6impl<'a> ResourceRef<'a> {
7    pub(super) fn new(cache: &'a Resource) -> Self {
8        ResourceRef {
9            data: cache.data.map_or(Data::Missing, |data| match data {
10                pipeline::Data::Buffer => Data::Buffer(&cache.buffer),
11                pipeline::Data::TooLarge { size } => Data::TooLarge { size },
12            }),
13            rela_path: cache.rela_path.as_ref(),
14            id: &cache.id,
15        }
16    }
17}
18
19/// The data of a mergeable resource, as it could be determined and computed previously.
20#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
21pub enum Data<'a> {
22    /// The object is missing, either because it didn't exist in the working tree or because its `id` was null.
23    /// Such data equals an empty buffer.
24    Missing,
25    /// The textual data as processed and ready for merging, i.e. suitable for storage in Git.
26    Buffer(&'a [u8]),
27    /// The file or blob is above the big-file threshold and cannot be processed.
28    ///
29    /// In this state, the file cannot be merged.
30    TooLarge {
31        /// The size of the object prior to performing any filtering or as it was found on disk.
32        ///
33        /// Note that technically, the size isn't always representative of the same 'state' of the
34        /// content, as once it can be the size of the blob in Git, and once it's the size of file
35        /// in the worktree.
36        size: u64,
37    },
38}
39
40impl<'a> Data<'a> {
41    /// Return ourselves as slice of bytes if this instance stores data.
42    /// Note that missing data is interpreted as empty slice, to facilitate additions and deletions.
43    pub fn as_slice(&self) -> Option<&'a [u8]> {
44        match self {
45            Data::Buffer(d) => Some(d),
46            Data::Missing => Some(&[]),
47            Data::TooLarge { .. } => None,
48        }
49    }
50}