1use std::cmp::Ordering;
2
3use crate::State;
4
5pub mod entries {
7 use bstr::BString;
8
9 #[derive(Debug, thiserror::Error)]
11 #[allow(missing_docs)]
12 pub enum Error {
13 #[error("Entry '{current_path}' (stage = {current_stage}) at index {current_index} should order after prior entry '{previous_path}' (stage = {previous_stage})")]
14 OutOfOrder {
15 current_index: usize,
16 current_path: BString,
17 current_stage: u8,
18 previous_path: BString,
19 previous_stage: u8,
20 },
21 }
22}
23
24pub mod extensions {
26 use crate::extension;
27
28 #[derive(Debug, thiserror::Error)]
30 #[allow(missing_docs)]
31 pub enum Error {
32 #[error(transparent)]
33 Tree(#[from] extension::tree::verify::Error),
34 }
35}
36
37impl State {
38 pub fn verify_entries(&self) -> Result<(), entries::Error> {
40 let _span = gix_features::trace::coarse!("gix_index::File::verify_entries()");
41 let mut previous = None::<&crate::Entry>;
42 for (idx, entry) in self.entries.iter().enumerate() {
43 if let Some(prev) = previous {
44 if prev.cmp(entry, self) != Ordering::Less {
45 return Err(entries::Error::OutOfOrder {
46 current_index: idx,
47 current_path: entry.path(self).into(),
48 current_stage: entry.flags.stage() as u8,
49 previous_path: prev.path(self).into(),
50 previous_stage: prev.flags.stage() as u8,
51 });
52 }
53 }
54 previous = Some(entry);
55 }
56 Ok(())
57 }
58
59 pub fn verify_extensions(&self, use_find: bool, objects: impl gix_object::Find) -> Result<(), extensions::Error> {
61 self.tree().map(|t| t.verify(use_find, objects)).transpose()?;
62 Ok(())
65 }
66}