Skip to content

Commit 2e04b71

Browse files
committed
refactor (#301)
1 parent c28f492 commit 2e04b71

File tree

5 files changed

+266
-266
lines changed

5 files changed

+266
-266
lines changed

git-worktree/src/index.rs

Lines changed: 0 additions & 245 deletions
This file was deleted.

git-worktree/src/index/checkout.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use bstr::BString;
2+
use quick_error::quick_error;
3+
4+
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5+
pub struct Collision {
6+
/// the path that collided with something already present on disk.
7+
pub path: BString,
8+
/// The io error we encountered when checking out `path`.
9+
pub error_kind: std::io::ErrorKind,
10+
}
11+
12+
pub struct Outcome {
13+
pub collisions: Vec<Collision>,
14+
}
15+
16+
#[derive(Clone, Copy)]
17+
pub struct Options {
18+
/// capabilities of the file system
19+
pub fs: crate::fs::Capabilities,
20+
/// If true, we assume no file to exist in the target directory, and want exclusive access to it.
21+
/// This should be enabled when cloning to avoid checks for freshness of files. This also enables
22+
/// detection of collisions based on whether or not exclusive file creation succeeds or fails.
23+
pub destination_is_initially_empty: bool,
24+
/// If true, default false, try to checkout as much as possible and don't abort on first error which isn't
25+
/// due to a conflict.
26+
/// The operation will never fail, but count the encountered errors instead along with their paths.
27+
pub keep_going: bool,
28+
/// If true, a files creation time is taken into consideration when checking if a file changed.
29+
/// Can be set to false in case other tools alter the creation time in ways that interfere with our operation.
30+
///
31+
/// Default true.
32+
pub trust_ctime: bool,
33+
/// If true, all stat fields will be used when checking for up-to-date'ness of the entry. Otherwise
34+
/// nano-second parts of mtime and ctime,uid, gid, inode and device number won't be used, leaving only
35+
/// the whole-second part of ctime and mtime and the file size to be checked.
36+
///
37+
/// Default true.
38+
pub check_stat: bool,
39+
}
40+
41+
impl Default for Options {
42+
fn default() -> Self {
43+
Options {
44+
fs: Default::default(),
45+
destination_is_initially_empty: false,
46+
keep_going: false,
47+
trust_ctime: true,
48+
check_stat: true,
49+
}
50+
}
51+
}
52+
53+
quick_error! {
54+
#[derive(Debug)]
55+
pub enum Error {
56+
IllformedUtf8{ path: BString } {
57+
display("Could not convert path to UTF8: {}", path)
58+
}
59+
Time(err: std::time::SystemTimeError) {
60+
from()
61+
source(err)
62+
display("The clock was off when reading file related metadata after updating a file on disk")
63+
}
64+
Io(err: std::io::Error) {
65+
from()
66+
source(err)
67+
display("IO error while writing blob or reading file metadata or changing filetype")
68+
}
69+
ObjectNotFound{ oid: git_hash::ObjectId, path: std::path::PathBuf } {
70+
display("object {} for checkout at {} not found in object database", oid.to_hex(), path.display())
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)