Skip to content

Commit 060d08b

Browse files
Muir Mandersfacebook-github-bot
authored andcommitted
clone: avoid hardcoded ".hg" when checking out
Summary: Use the dot dir instead of repo root so we don't have to figure out the dot dir name. Reviewed By: DurhamG Differential Revision: D39040643 fbshipit-source-id: 58802b7505870046d4bc51c6397d1871997f8964
1 parent 0a3a6d5 commit 060d08b

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

eden/scm/lib/checkout/src/clone.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::sync::Arc;
1313
use std::time::SystemTime;
1414

1515
use anyhow::anyhow;
16+
use anyhow::bail;
1617
use anyhow::Context;
1718
use configmodel::convert::ByteCount;
1819
use configmodel::Config;
@@ -83,10 +84,10 @@ pub struct CheckoutError {
8384
}
8485

8586
/// 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)]
8788
pub fn checkout(
8889
config: &dyn Config,
89-
wc_path: &Path,
90+
dot_path: &Path,
9091
source_mf: &TreeManifest,
9192
target_mf: &TreeManifest,
9293
file_store: Arc<dyn ReadFileContents<Error = anyhow::Error> + Send + Sync>,
@@ -96,7 +97,7 @@ pub fn checkout(
9697
let mut state = CheckoutState::default();
9798
state
9899
.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,
100101
)
101102
.map_err(|err| CheckoutError {
102103
resumable: state.resumable,
@@ -113,20 +114,23 @@ impl CheckoutState {
113114
fn checkout(
114115
&mut self,
115116
config: &dyn Config,
116-
wc_path: &Path,
117+
dot_path: &Path,
117118
source_mf: &TreeManifest,
118119
target_mf: &TreeManifest,
119120
file_store: Arc<dyn ReadFileContents<Error = anyhow::Error> + Send + Sync>,
120121
ts: &mut TreeState,
121122
target: HgId,
122123
) -> 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+
};
124128

125-
let _wlock = repolock::lock_working_copy(config, &dot_hg)?;
129+
let _wlock = repolock::lock_working_copy(config, dot_path)?;
126130

127131
let mut sparse_overrides = None;
128132

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")) {
130134
Ok(contents) => {
131135
let overrides = sparse::config_overrides(config);
132136
sparse_overrides = Some(overrides.clone());
@@ -156,14 +160,14 @@ impl CheckoutState {
156160
// Write out overrides first so they don't change when resuming
157161
// this checkout.
158162
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| {
160164
serde_json::to_writer(f, &sparse_overrides)?;
161165
Ok(())
162166
})?;
163167
}
164168

165169
if config.get_or_default("checkout", "resumable")? {
166-
let progress_path = dot_hg.join("updateprogress");
170+
let progress_path = dot_path.join("updateprogress");
167171
plan.add_progress(&progress_path).with_context(|| {
168172
format!(
169173
"error loading checkout progress '{}'",
@@ -173,7 +177,7 @@ impl CheckoutState {
173177
self.resumable = true;
174178
}
175179

176-
atomic_write(&dot_hg.join("updatestate"), |f| {
180+
atomic_write(&dot_path.join("updatestate"), |f| {
177181
f.write_all(target.to_hex().as_bytes())
178182
})?;
179183

@@ -185,9 +189,9 @@ impl CheckoutState {
185189
ts.set_metadata(&ts_buf);
186190

187191
update_dirstate(&plan, ts, &vfs)?;
188-
flush_dirstate(config, ts, &dot_hg, target)?;
192+
flush_dirstate(config, ts, dot_path, target)?;
189193

190-
remove_file(dot_hg.join("updatestate"))?;
194+
remove_file(dot_path.join("updatestate"))?;
191195

192196
Ok(CheckoutStats {
193197
updated: plan.stats().0,

eden/scm/lib/clone/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub fn init_working_copy(
129129

130130
match checkout::clone::checkout(
131131
repo.config(),
132-
repo.path(),
132+
repo.dot_hg_path(),
133133
&source_mf,
134134
&target_mf,
135135
file_store.clone(),

eden/scm/tests/test-identity.t

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#chg-compatible
22
#debugruntest-compatible
33

4-
$ configure modern
4+
$ configure modernclient
55
$ setconfig clone.use-rust=true
66

77
$ newrepo
@@ -35,7 +35,9 @@ Init can create a ".sl" repo.
3535
$ hg push -r . --to master --create -q
3636

3737
Clone can create a ".sl" repo.
38-
$ HGIDENTITY=sl hg clone -Uq eager:clone_me cloned
38+
$ HGIDENTITY=sl hg clone -q test:clone_me cloned
39+
$ find cloned
40+
cloned/foo
3941
$ ls cloned/.hg
4042
$ ls cloned/.sl
4143
00changelog.i
@@ -46,3 +48,6 @@ Clone can create a ".sl" repo.
4648
requires
4749
store
4850
treestate
51+
updateprogress
52+
wlock.data
53+
wlock.lock

0 commit comments

Comments
 (0)