Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4bdd1f

Browse files
codexByron
andcommitted
feat(gix-index): greatly improve the index File debug output.
This allows tests to rely on it more with insta, and not miss a thing. Co-authored-by: Sebastian Thiel <[email protected]>
1 parent 69d644e commit e4bdd1f

7 files changed

Lines changed: 458 additions & 224 deletions

File tree

gix-index/src/file/mod.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,64 @@ mod impls {
2121
mod impl_ {
2222
use std::fmt::Formatter;
2323

24-
use crate::{File, State};
24+
use crate::{Entry, File, PathStorageRef, State};
2525

2626
impl std::fmt::Debug for File {
2727
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28+
if f.alternate() {
29+
return f
30+
.debug_struct("File")
31+
.field("path", &self.path.display())
32+
.field("checksum", &self.checksum)
33+
.field("object_hash", &self.state.object_hash)
34+
.field("timestamp", &self.state.timestamp)
35+
.field("version", &self.state.version)
36+
.field(
37+
"entries",
38+
&EntriesDebug {
39+
entries: &self.state.entries,
40+
path_backing: &self.state.path_backing,
41+
},
42+
)
43+
.field("path_backing_size_bytes", &self.state.path_backing.len())
44+
.field("is_sparse", &self.state.is_sparse)
45+
.field("end_of_index_at_decode_time", &self.state.end_of_index_at_decode_time)
46+
.field("offset_table_at_decode_time", &self.state.offset_table_at_decode_time)
47+
.field("tree", &self.state.tree)
48+
.field("has_link", &self.state.link.is_some())
49+
.field("has_resolve_undo", &self.state.resolve_undo.is_some())
50+
.field("untracked", &self.state.untracked)
51+
.field("has_fs_monitor", &self.state.fs_monitor.is_some())
52+
.finish();
53+
}
2854
f.debug_struct("File")
2955
.field("path", &self.path.display())
3056
.field("checksum", &self.checksum)
3157
.finish_non_exhaustive()
3258
}
3359
}
3460

61+
struct EntriesDebug<'a> {
62+
entries: &'a [Entry],
63+
path_backing: &'a PathStorageRef,
64+
}
65+
66+
impl std::fmt::Debug for EntriesDebug<'_> {
67+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
68+
if !f.alternate() {
69+
return f.debug_list().entries(self.entries).finish();
70+
}
71+
72+
writeln!(f, "[")?;
73+
for entry in self.entries {
74+
write!(f, " ")?;
75+
entry.fmt_debug(f, Some(self.path_backing))?;
76+
writeln!(f, ",")?;
77+
}
78+
write!(f, "]")
79+
}
80+
}
81+
3582
impl From<File> for State {
3683
fn from(f: File) -> Self {
3784
f.state

gix-index/src/lib.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub enum Version {
5353
}
5454

5555
/// An entry in the index, identifying a non-tree item on disk.
56-
#[derive(Debug, Clone, Eq, PartialEq)]
56+
#[derive(Clone, Eq, PartialEq)]
5757
pub struct Entry {
5858
/// The filesystem stat information for the file on disk.
5959
pub stat: entry::Stat,
@@ -165,7 +165,54 @@ pub struct State {
165165
mod impls {
166166
use std::fmt::{Debug, Formatter};
167167

168-
use crate::{State, entry::Stage};
168+
use crate::{Entry, PathStorageRef, State, entry::Stage};
169+
170+
impl Entry {
171+
pub(crate) fn fmt_debug(&self, f: &mut Formatter, path_backing: Option<&PathStorageRef>) -> std::fmt::Result {
172+
if f.alternate() {
173+
write!(
174+
f,
175+
"{} {}{:?} mtime: {:?} {} ",
176+
match self.flags.stage() {
177+
Stage::Unconflicted => " ",
178+
Stage::Base => "BASE ",
179+
Stage::Ours => "OURS ",
180+
Stage::Theirs => "THEIRS ",
181+
},
182+
if self.flags.is_empty() {
183+
"".to_string()
184+
} else {
185+
format!("{:?} ", self.flags)
186+
},
187+
self.mode,
188+
self.stat.mtime,
189+
self.id,
190+
)?;
191+
return match path_backing {
192+
Some(path_backing) => write!(f, "{}", self.path_in(path_backing)),
193+
None => write!(f, "{:?}", self.path),
194+
};
195+
}
196+
197+
let mut entry = f.debug_struct("Entry");
198+
entry
199+
.field("stat", &self.stat)
200+
.field("id", &self.id)
201+
.field("flags", &self.flags)
202+
.field("mode", &self.mode);
203+
match path_backing {
204+
Some(path_backing) => entry.field("path", &self.path_in(path_backing)),
205+
None => entry.field("path", &self.path),
206+
}
207+
.finish()
208+
}
209+
}
210+
211+
impl Debug for Entry {
212+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
213+
self.fmt_debug(f, None)
214+
}
215+
}
169216

170217
impl Debug for State {
171218
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)