1
1
#![ forbid( unsafe_code, rust_2018_idioms) ]
2
- //! Git Worktree
3
2
4
3
use git_hash:: oid;
5
4
use git_object:: bstr:: ByteSlice ;
@@ -10,9 +9,6 @@ use std::io::Write;
10
9
use std:: path:: { Path , PathBuf } ;
11
10
use std:: time:: Duration ;
12
11
13
- #[ cfg( unix) ]
14
- use std:: os:: unix:: fs:: OpenOptionsExt ;
15
-
16
12
quick_error ! {
17
13
#[ derive( Debug ) ]
18
14
pub enum Error {
@@ -39,28 +35,34 @@ quick_error! {
39
35
}
40
36
41
37
/// Copy index to `path`
42
- pub fn copy_index < P , Find > ( state : & mut git_index:: State , path : P , mut find : Find , opts : Options ) -> Result < ( ) , Error >
38
+ pub fn copy_index < Find > (
39
+ index : & mut git_index:: State ,
40
+ path : impl AsRef < Path > ,
41
+ mut find : Find ,
42
+ opts : Options ,
43
+ ) -> Result < ( ) , Error >
43
44
where
44
- P : AsRef < Path > ,
45
45
Find : for < ' a > FnMut ( & oid , & ' a mut Vec < u8 > ) -> Option < git_object:: BlobRef < ' a > > ,
46
46
{
47
47
let path = path. as_ref ( ) ;
48
48
let mut buf = Vec :: new ( ) ;
49
49
let mut entry_time = Vec :: new ( ) ; // Entries whose timestamps have to be updated
50
- for ( i, entry) in state . entries ( ) . iter ( ) . enumerate ( ) {
50
+ for ( i, entry) in index . entries ( ) . iter ( ) . enumerate ( ) {
51
51
if entry. flags . contains ( git_index:: entry:: Flags :: SKIP_WORKTREE ) {
52
52
continue ;
53
53
}
54
- let entry_path = entry. path ( state ) . to_path ( ) ?;
54
+ let entry_path = entry. path ( index ) . to_path ( ) ?;
55
55
let dest = path. join ( entry_path) ;
56
56
create_dir_all ( dest. parent ( ) . expect ( "entry paths are never empty" ) ) ?;
57
+
57
58
match entry. mode {
58
59
git_index:: entry:: Mode :: FILE | git_index:: entry:: Mode :: FILE_EXECUTABLE => {
59
60
let obj = find ( & entry. id , & mut buf) . ok_or_else ( || Error :: NotFound ( entry. id , path. to_path_buf ( ) ) ) ?;
60
61
let mut options = OpenOptions :: new ( ) ;
61
62
options. write ( true ) . create_new ( true ) ;
62
63
#[ cfg( unix) ]
63
64
if entry. mode == git_index:: entry:: Mode :: FILE_EXECUTABLE {
65
+ use std:: os:: unix:: fs:: OpenOptionsExt ;
64
66
options. mode ( 0o777 ) ;
65
67
}
66
68
let mut file = options. open ( & dest) ?;
@@ -105,7 +107,7 @@ where
105
107
_ => unreachable ! ( ) ,
106
108
}
107
109
}
108
- let entries = state . entries_mut ( ) ;
110
+ let entries = index . entries_mut ( ) ;
109
111
for ( ctime, mtime, i) in entry_time {
110
112
let stat = & mut entries[ i] . stat ;
111
113
stat. mtime . secs = u32:: try_from ( mtime. as_secs ( ) ) ?;
0 commit comments