1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use git_hash::ObjectId;
use git_object::bstr::BString;
use std::fmt::Formatter;
use crate::{
store_impl::{file, file::Transaction},
transaction::RefEdit,
};
pub type FindObjectFn<'a> = dyn FnMut(
git_hash::ObjectId,
&mut Vec<u8>,
) -> Result<Option<git_object::Kind>, Box<dyn std::error::Error + Send + Sync + 'static>>
+ 'a;
pub enum PackedRefs<'a> {
DeletionsOnly,
DeletionsAndNonSymbolicUpdates(Box<FindObjectFn<'a>>),
DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(Box<FindObjectFn<'a>>),
}
impl Default for PackedRefs<'_> {
fn default() -> Self {
PackedRefs::DeletionsOnly
}
}
#[derive(Debug)]
pub(in crate::store_impl::file) struct Edit {
update: RefEdit,
lock: Option<git_lock::Marker>,
parent_index: Option<usize>,
leaf_referent_previous_oid: Option<ObjectId>,
}
impl Edit {
fn name(&self) -> BString {
self.update.name.0.clone()
}
}
impl std::borrow::Borrow<RefEdit> for Edit {
fn borrow(&self) -> &RefEdit {
&self.update
}
}
impl std::borrow::BorrowMut<RefEdit> for Edit {
fn borrow_mut(&mut self) -> &mut RefEdit {
&mut self.update
}
}
impl file::Store {
pub fn transaction(&self) -> Transaction<'_, '_> {
Transaction {
store: self,
packed_transaction: None,
updates: None,
packed_refs: PackedRefs::default(),
}
}
}
impl<'s, 'p> Transaction<'s, 'p> {
pub fn packed_refs(mut self, packed_refs: PackedRefs<'p>) -> Self {
self.packed_refs = packed_refs;
self
}
}
impl std::fmt::Debug for Transaction<'_, '_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Transaction")
.field("store", self.store)
.field("edits", &self.updates.as_ref().map(|u| u.len()))
.finish_non_exhaustive()
}
}
pub mod prepare;
pub mod commit;