Trait git_odb::Write

source ·
pub trait Write {
    type Error: Error + From<Error>;

    fn write_stream(
        &self,
        kind: Kind,
        size: u64,
        from: impl Read
    ) -> Result<ObjectId, Self::Error>; fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> { ... } fn write_buf(
        &self,
        object: Kind,
        from: &[u8]
    ) -> Result<ObjectId, Self::Error> { ... } }
Expand description

Describe the capability to write git objects into an object store.

Required Associated Types§

The error type used for all trait methods.

Note the default implementations require the From<io::Error> bound.

Required Methods§

As write, but takes an input stream. This is commonly used for writing blobs directly without reading them to memory first.

Provided Methods§

Write objects using the intrinsic kind of hash into the database, returning id to reference it in subsequent reads.

Examples found in repository?
src/traits.rs (line 81)
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
        fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
            (*self).write(object)
        }

        fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
            (*self).write_buf(object, from)
        }

        fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
            (*self).write_stream(kind, size, from)
        }
    }

    impl<T> crate::Write for Arc<T>
    where
        T: crate::Write,
    {
        type Error = T::Error;

        fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
            self.deref().write(object)
        }

        fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
            self.deref().write_buf(object, from)
        }

        fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
            self.deref().write_stream(kind, size, from)
        }
    }

    impl<T> crate::Write for Rc<T>
    where
        T: crate::Write,
    {
        type Error = T::Error;

        fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
            self.deref().write(object)
        }

As write, but takes an object kind along with its encoded bytes.

Examples found in repository?
src/traits.rs (line 85)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
        fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
            (*self).write_buf(object, from)
        }

        fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
            (*self).write_stream(kind, size, from)
        }
    }

    impl<T> crate::Write for Arc<T>
    where
        T: crate::Write,
    {
        type Error = T::Error;

        fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
            self.deref().write(object)
        }

        fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
            self.deref().write_buf(object, from)
        }

        fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
            self.deref().write_stream(kind, size, from)
        }
    }

    impl<T> crate::Write for Rc<T>
    where
        T: crate::Write,
    {
        type Error = T::Error;

        fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
            self.deref().write(object)
        }

        fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
            self.deref().write_buf(object, from)
        }
More examples
Hide additional examples
src/store_impls/loose/verify.rs (line 62)
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    pub fn verify_integrity(
        &self,
        mut progress: impl Progress,
        should_interrupt: &AtomicBool,
    ) -> Result<integrity::Statistics, integrity::Error> {
        let mut buf = Vec::new();
        let sink = crate::sink(self.object_hash);

        let mut num_objects = 0;
        let start = Instant::now();
        let mut progress = progress.add_child_with_id("Validating", *b"VILO"); /* Verify Integrity Loose Objects */
        progress.init(None, git_features::progress::count("loose objects"));
        for id in self.iter().filter_map(Result::ok) {
            let object = self
                .try_find(id, &mut buf)
                .map_err(|_| integrity::Error::Retry)?
                .ok_or(integrity::Error::Retry)?;
            let actual_id = sink.write_buf(object.kind, object.data).expect("sink never fails");
            if actual_id != id {
                return Err(integrity::Error::ObjectHashMismatch {
                    kind: object.kind,
                    actual: actual_id,
                    expected: id,
                });
            }
            object.decode().map_err(|err| integrity::Error::ObjectDecode {
                source: err,
                kind: object.kind,
                id,
            })?;

            progress.inc();
            num_objects += 1;
            if should_interrupt.load(Ordering::SeqCst) {
                return Err(integrity::Error::Interrupted);
            }
        }
        progress.show_throughput(start);

        Ok(integrity::Statistics { num_objects })
    }

Implementations on Foreign Types§

Implementors§