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
use std::path::PathBuf;
use crate::store::{file, packed};
impl file::Store {
pub(crate) fn packed_transaction(
&self,
lock_mode: git_lock::acquire::Fail,
) -> Result<packed::Transaction, transaction::Error> {
let lock = git_lock::File::acquire_to_update_resource(self.packed_refs_path(), lock_mode, None)?;
Ok(match self.packed()? {
Some(packed) => packed::Transaction::new_from_pack_and_lock(packed, lock),
None => packed::Transaction::new_empty(lock),
})
}
pub fn packed(&self) -> Result<Option<packed::Buffer>, packed::buffer::open::Error> {
match packed::Buffer::open(self.packed_refs_path(), 32 * 1024) {
Ok(buf) => Ok(Some(buf)),
Err(packed::buffer::open::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(err) => Err(err),
}
}
pub fn packed_refs_path(&self) -> PathBuf {
self.base.join("packed-refs")
}
}
pub mod transaction {
use crate::store::packed;
use quick_error::quick_error;
quick_error! {
#[derive(Debug)]
#[allow(missing_docs)]
pub enum Error {
BufferOpen(err: packed::buffer::open::Error) {
display("An existing pack couldn't be opened or read when preparing a transaction")
source(err)
from()
}
TransactionLock(err: git_lock::acquire::Error) {
display("The lock for a packed transaction could not be obtained")
source(err)
from()
}
}
}
}