gix_worktree_state/checkout/mod.rs
1use bstr::BString;
2use gix_index::entry::stat;
3
4/// Information about a path that failed to checkout as something else was already present.
5#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
6pub struct Collision {
7 /// the path that collided with something already present on disk.
8 pub path: BString,
9 /// The io error we encountered when checking out `path`.
10 pub error_kind: std::io::ErrorKind,
11}
12
13/// A path that encountered an IO error.
14#[derive(Debug)]
15pub struct ErrorRecord {
16 /// the path that encountered the error.
17 pub path: BString,
18 /// The error
19 pub error: Box<dyn std::error::Error + Send + Sync + 'static>,
20}
21
22/// The outcome of checking out an entire index.
23#[derive(Debug, Default)]
24pub struct Outcome {
25 /// The amount of files updated, or created.
26 pub files_updated: usize,
27 /// The amount of bytes written to disk,
28 pub bytes_written: u64,
29 /// The encountered collisions, which can happen on a case-insensitive filesystem.
30 pub collisions: Vec<Collision>,
31 /// Other errors that happened during checkout.
32 pub errors: Vec<ErrorRecord>,
33 /// Relative paths that the process listed as 'delayed' even though we never passed them.
34 pub delayed_paths_unknown: Vec<BString>,
35 /// All paths that were left unprocessed, because they were never listed by the process even though we passed them.
36 pub delayed_paths_unprocessed: Vec<BString>,
37}
38
39/// Options to further configure the checkout operation.
40#[derive(Clone, Default)]
41pub struct Options {
42 /// capabilities of the file system
43 pub fs: gix_fs::Capabilities,
44 /// Options to configure how to validate path components.
45 pub validate: gix_worktree::validate::path::component::Options,
46 /// If set, don't use more than this amount of threads.
47 /// Otherwise, usually use as many threads as there are logical cores.
48 /// A value of 0 is interpreted as no-limit
49 pub thread_limit: Option<usize>,
50 /// If true, we assume no file to exist in the target directory, and want exclusive access to it.
51 /// This should be enabled when cloning to avoid checks for freshness of files. This also enables
52 /// detection of collisions based on whether or not exclusive file creation succeeds or fails.
53 pub destination_is_initially_empty: bool,
54 /// If true, default false, worktree entries on disk will be overwritten with content from the index
55 /// even if they appear to be changed. When creating directories that clash with existing worktree entries,
56 /// these will try to delete the existing entry.
57 /// This is similar in behaviour as `git checkout --force`.
58 pub overwrite_existing: bool,
59 /// If true, default false, try to checkout as much as possible and don't abort on first error which isn't
60 /// due to a conflict.
61 /// The checkout operation will never fail, but count the encountered errors instead along with their paths.
62 pub keep_going: bool,
63 /// Control how stat comparisons are made when checking if a file is fresh.
64 pub stat_options: stat::Options,
65 /// A stack of attributes to use with the filesystem cache to use as driver for filters.
66 pub attributes: gix_worktree::stack::state::Attributes,
67 /// The filter pipeline to use for applying mandatory filters before writing to the worktree.
68 pub filters: gix_filter::Pipeline,
69 /// Control how long-running processes may use the 'delay' capability.
70 pub filter_process_delay: gix_filter::driver::apply::Delay,
71}
72
73/// The error returned by the [checkout()][crate::checkout()] function.
74#[derive(Debug, thiserror::Error)]
75#[allow(missing_docs)]
76pub enum Error {
77 #[error("Could not convert path to UTF8: {}", .path)]
78 IllformedUtf8 { path: BString },
79 #[error("The clock was off when reading file related metadata after updating a file on disk")]
80 Time(#[from] std::time::SystemTimeError),
81 #[error("IO error while writing blob or reading file metadata or changing filetype")]
82 Io(#[from] std::io::Error),
83 #[error("object for checkout at {} could not be retrieved from object database", .path.display())]
84 Find {
85 #[source]
86 err: gix_object::find::existing_object::Error,
87 path: std::path::PathBuf,
88 },
89 #[error(transparent)]
90 Filter(#[from] gix_filter::pipeline::convert::to_worktree::Error),
91 #[error(transparent)]
92 FilterListDelayed(#[from] gix_filter::driver::delayed::list::Error),
93 #[error(transparent)]
94 FilterFetchDelayed(#[from] gix_filter::driver::delayed::fetch::Error),
95 #[error("The entry at path '{rela_path}' was listed as delayed by the filter process, but we never passed it")]
96 FilterPathUnknown { rela_path: BString },
97 #[error("The following paths were delayed and apparently forgotten to be processed by the filter driver: ")]
98 FilterPathsUnprocessed { rela_paths: Vec<BString> },
99}
100
101mod chunk;
102mod entry;
103pub(crate) mod function;