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
use std::path::PathBuf;

/// The way a file store handles the reflog
#[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone, Copy)]
pub enum WriteReflog {
    /// Write a ref log for ref edits according to the standard rules.
    Normal,
    /// Never write a ref log.
    Disable,
}

impl Default for WriteReflog {
    fn default() -> Self {
        WriteReflog::Normal
    }
}

/// A store for reference which uses plain files.
///
/// Each ref is represented as a single file on disk in a folder structure that follows the relative path
/// used to identify [references][Reference].
#[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)]
pub struct Store {
    /// The location at which loose references can be found as per conventions of a typical git repository.
    ///
    /// Typical base paths are `.git` repository folders.
    pub base: PathBuf,
    /// The way to handle reflog edits
    pub write_reflog: WriteReflog,
}

/// A transaction on a file store
pub struct Transaction<'s> {
    store: &'s Store,
    packed_transaction: Option<crate::store::packed::Transaction>,
    updates: Option<Vec<transaction::Edit>>,
    packed_refs: transaction::PackedRefs,
    namespace: Option<crate::Namespace>,
}

pub(in crate::store::file) fn path_to_name(path: impl Into<PathBuf>) -> bstr::BString {
    use os_str_bytes::OsStringBytes;
    let path = path.into().into_raw_vec();
    #[cfg(windows)]
    let path = {
        use bstr::ByteSlice;
        path.replace(b"\\", b"/")
    };
    path.into()
}

///
pub mod loose;
mod overlay;

///
pub mod iter {
    pub use super::{
        loose::iter::{loose, Loose},
        overlay::LooseThenPacked,
    };

    ///
    pub mod loose_then_packed {
        pub use super::super::overlay::Error;
    }
}

///
pub mod log;

///
pub mod find;

mod reference;
pub use reference::Reference;

///
pub mod transaction;

///
pub mod packed;