@@ -13,6 +13,7 @@ use std::sync::Arc;
13
13
use std:: time:: SystemTime ;
14
14
15
15
use anyhow:: anyhow;
16
+ use anyhow:: bail;
16
17
use anyhow:: Context ;
17
18
use configmodel:: convert:: ByteCount ;
18
19
use configmodel:: Config ;
@@ -83,10 +84,10 @@ pub struct CheckoutError {
83
84
}
84
85
85
86
/// A somewhat simplified/specialized checkout suitable for use during a clone.
86
- #[ instrument( skip_all, fields( path=%wc_path . display( ) , %target) , err) ]
87
+ #[ instrument( skip_all, fields( path=%dot_path . display( ) , %target) , err) ]
87
88
pub fn checkout (
88
89
config : & dyn Config ,
89
- wc_path : & Path ,
90
+ dot_path : & Path ,
90
91
source_mf : & TreeManifest ,
91
92
target_mf : & TreeManifest ,
92
93
file_store : Arc < dyn ReadFileContents < Error = anyhow:: Error > + Send + Sync > ,
@@ -96,7 +97,7 @@ pub fn checkout(
96
97
let mut state = CheckoutState :: default ( ) ;
97
98
state
98
99
. checkout (
99
- config, wc_path , source_mf, target_mf, file_store, ts, target,
100
+ config, dot_path , source_mf, target_mf, file_store, ts, target,
100
101
)
101
102
. map_err ( |err| CheckoutError {
102
103
resumable : state. resumable ,
@@ -113,20 +114,23 @@ impl CheckoutState {
113
114
fn checkout (
114
115
& mut self ,
115
116
config : & dyn Config ,
116
- wc_path : & Path ,
117
+ dot_path : & Path ,
117
118
source_mf : & TreeManifest ,
118
119
target_mf : & TreeManifest ,
119
120
file_store : Arc < dyn ReadFileContents < Error = anyhow:: Error > + Send + Sync > ,
120
121
ts : & mut TreeState ,
121
122
target : HgId ,
122
123
) -> anyhow:: Result < CheckoutStats > {
123
- let dot_hg = wc_path. join ( ".hg" ) ;
124
+ let wc_path = match dot_path. parent ( ) {
125
+ Some ( p) => p,
126
+ None => bail ! ( "invalid dot path {}" , dot_path. display( ) ) ,
127
+ } ;
124
128
125
- let _wlock = repolock:: lock_working_copy ( config, & dot_hg ) ?;
129
+ let _wlock = repolock:: lock_working_copy ( config, dot_path ) ?;
126
130
127
131
let mut sparse_overrides = None ;
128
132
129
- let matcher: Box < dyn Matcher > = match util:: file:: read_to_string ( dot_hg . join ( "sparse" ) ) {
133
+ let matcher: Box < dyn Matcher > = match util:: file:: read_to_string ( dot_path . join ( "sparse" ) ) {
130
134
Ok ( contents) => {
131
135
let overrides = sparse:: config_overrides ( config) ;
132
136
sparse_overrides = Some ( overrides. clone ( ) ) ;
@@ -156,14 +160,14 @@ impl CheckoutState {
156
160
// Write out overrides first so they don't change when resuming
157
161
// this checkout.
158
162
if let Some ( sparse_overrides) = sparse_overrides {
159
- atomic_write ( & dot_hg . join ( CONFIG_OVERRIDE_CACHE ) , |f| {
163
+ atomic_write ( & dot_path . join ( CONFIG_OVERRIDE_CACHE ) , |f| {
160
164
serde_json:: to_writer ( f, & sparse_overrides) ?;
161
165
Ok ( ( ) )
162
166
} ) ?;
163
167
}
164
168
165
169
if config. get_or_default ( "checkout" , "resumable" ) ? {
166
- let progress_path = dot_hg . join ( "updateprogress" ) ;
170
+ let progress_path = dot_path . join ( "updateprogress" ) ;
167
171
plan. add_progress ( & progress_path) . with_context ( || {
168
172
format ! (
169
173
"error loading checkout progress '{}'" ,
@@ -173,7 +177,7 @@ impl CheckoutState {
173
177
self . resumable = true ;
174
178
}
175
179
176
- atomic_write ( & dot_hg . join ( "updatestate" ) , |f| {
180
+ atomic_write ( & dot_path . join ( "updatestate" ) , |f| {
177
181
f. write_all ( target. to_hex ( ) . as_bytes ( ) )
178
182
} ) ?;
179
183
@@ -185,9 +189,9 @@ impl CheckoutState {
185
189
ts. set_metadata ( & ts_buf) ;
186
190
187
191
update_dirstate ( & plan, ts, & vfs) ?;
188
- flush_dirstate ( config, ts, & dot_hg , target) ?;
192
+ flush_dirstate ( config, ts, dot_path , target) ?;
189
193
190
- remove_file ( dot_hg . join ( "updatestate" ) ) ?;
194
+ remove_file ( dot_path . join ( "updatestate" ) ) ?;
191
195
192
196
Ok ( CheckoutStats {
193
197
updated : plan. stats ( ) . 0 ,
0 commit comments