forked from GitoxideLabs/gitoxide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
137 lines (118 loc) · 4.13 KB
/
Copy pathmod.rs
File metadata and controls
137 lines (118 loc) · 4.13 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
mod impls {
use std::ops::{Deref, DerefMut};
use crate::{File, State};
impl Deref for File {
type Target = State;
fn deref(&self) -> &Self::Target {
&self.state
}
}
impl DerefMut for File {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.state
}
}
}
mod impl_ {
use std::fmt::Formatter;
use crate::{Entry, File, PathStorageRef, State};
impl std::fmt::Debug for File {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if f.alternate() {
return f
.debug_struct("File")
.field("path", &self.path.display())
.field("checksum", &self.checksum)
.field("object_hash", &self.state.object_hash)
.field("timestamp", &self.state.timestamp)
.field("version", &self.state.version)
.field(
"entries",
&EntriesDebug {
entries: &self.state.entries,
path_backing: &self.state.path_backing,
},
)
.field("path_backing_size_bytes", &self.state.path_backing.len())
.field("is_sparse", &self.state.is_sparse)
.field("end_of_index_at_decode_time", &self.state.end_of_index_at_decode_time)
.field("offset_table_at_decode_time", &self.state.offset_table_at_decode_time)
.field("tree", &self.state.tree)
.field("has_link", &self.state.link.is_some())
.field("has_resolve_undo", &self.state.resolve_undo.is_some())
.field("untracked", &self.state.untracked)
.field("has_fs_monitor", &self.state.fs_monitor.is_some())
.finish();
}
f.debug_struct("File")
.field("path", &self.path.display())
.field("checksum", &self.checksum)
.finish_non_exhaustive()
}
}
struct EntriesDebug<'a> {
entries: &'a [Entry],
path_backing: &'a PathStorageRef,
}
impl std::fmt::Debug for EntriesDebug<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if !f.alternate() {
return f.debug_list().entries(self.entries).finish();
}
writeln!(f, "[")?;
for entry in self.entries {
write!(f, " ")?;
entry.fmt_debug(f, Some(self.path_backing))?;
writeln!(f, ",")?;
}
write!(f, "]")
}
}
impl From<File> for State {
fn from(f: File) -> Self {
f.state
}
}
}
mod access {
use crate::File;
/// Consumption
impl File {
/// Take all non-copy parts of the index.
pub fn into_parts(self) -> (crate::State, std::path::PathBuf) {
(self.state, self.path)
}
}
/// Access
impl File {
/// The path from which the index was read or to which it is supposed to be written when used with [`File::from_state()`].
pub fn path(&self) -> &std::path::Path {
&self.path
}
/// The checksum over the file that was read or written to disk, or `None` if the state in memory was never serialized.
///
/// Note that even if `Some`, it will only represent the state in memory right after reading or [writing][File::write()].
pub fn checksum(&self) -> Option<gix_hash::ObjectId> {
self.checksum
}
}
}
mod mutation {
use std::path::PathBuf;
use crate::File;
/// Mutating access
impl File {
/// Set the path at which we think we are located to the given `path`.
///
/// This is useful to change the location of the index *once* it is written via [`write()`][File::write()].
pub fn set_path(&mut self, path: impl Into<PathBuf>) {
self.path = path.into();
}
}
}
///
pub mod init;
///
pub mod verify;
///
pub mod write;