Skip to content

Commit ed634ef

Browse files
Muir Mandersfacebook-github-bot
authored andcommitted
fix various hard coded ".hg" usages in Rust
Summary: Use the identity instead of hard coded ".hg". Reviewed By: DurhamG Differential Revision: D39040641 fbshipit-source-id: cb90040e36d33e2039965a51d37fa743175aa2b0
1 parent 060d08b commit ed634ef

File tree

9 files changed

+38
-17
lines changed

9 files changed

+38
-17
lines changed

eden/scm/lib/backingstore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ configparser = { version = "0.1.0", path = "../configparser" }
1515
eagerepo = { version = "0.1.0", path = "../eagerepo" }
1616
edenapi = { version = "0.1.0", path = "../edenapi" }
1717
env_logger = "0.7"
18+
identity = { version = "0.1.0", path = "../identity" }
1819
libc = "0.2.121"
1920
log = { version = "0.4.14", features = ["kv_unstable", "kv_unstable_std"] }
2021
manifest = { version = "0.1.0", path = "../manifest" }

eden/scm/lib/backingstore/src/backingstore/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ impl BackingStore {
4343
config.set("edenapi", "max-retry-per-request", Some("0"), &source);
4444
}
4545

46-
let hg = root.join(".hg");
46+
let ident = identity::must_sniff_dir(root)?;
47+
let dot_path = root.join(ident.dot_dir());
4748

4849
Ok(if config.get_or_default("scmstore", "backingstore")? {
49-
New(BackingScmStores::new(&config, &hg, use_edenapi, aux_data)?)
50+
New(BackingScmStores::new(
51+
&config,
52+
&dot_path,
53+
use_edenapi,
54+
aux_data,
55+
)?)
5056
} else {
51-
Old(BackingContentStores::new(&config, &hg, use_edenapi)?)
57+
Old(BackingContentStores::new(&config, &dot_path, use_edenapi)?)
5258
})
5359
}
5460

eden/scm/lib/clidispatch/src/dispatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn initialize_blackbox(optional_repo: &OptionalRepo) -> Result<()> {
131131
})?
132132
.value();
133133
let max_files = config.get_or("blackbox", "maxfiles", || 3)?;
134-
let path = repo.shared_path().join(".hg/blackbox/v1");
134+
let path = repo.shared_dot_hg_path().join("blackbox/v1");
135135
if let Ok(blackbox) = ::blackbox::BlackboxOptions::new()
136136
.max_bytes_per_log(max_size)
137137
.max_log_count(max_files as u8)

eden/scm/lib/edenfs-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ anyhow = "1.0.56"
1010
byteorder = "1.3"
1111
chrono = { version = "0.4", features = ["clock", "serde", "std"], default-features = false }
1212
fbthrift_socket = { version = "0.1.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
13+
identity = { version = "0.1.0", path = "../identity" }
1314
io = { version = "0.1.0", path = "../io" }
1415
sha2 = "0.10"
1516
status = { version = "0.1.0", path = "../status" }

eden/scm/lib/edenfs-client/src/status.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ pub struct OperationNotSupported;
6363
/// - Print status (Move to another crate).
6464
/// - Avoid `print!` directly. Use `clidispatch::io` instead.
6565
pub fn maybe_status_fastpath(
66-
repo_root: &Path,
66+
repo_dot_path: &Path,
6767
io: &IO,
6868
list_ignored: bool,
6969
) -> Result<(status::Status, HashMap<RepoPathBuf, RepoPathBuf>)> {
7070
let rt = tokio::runtime::Runtime::new()?;
7171

72-
rt.block_on(maybe_status_fastpath_internal(repo_root, io, list_ignored))
72+
rt.block_on(maybe_status_fastpath_internal(
73+
repo_dot_path,
74+
io,
75+
list_ignored,
76+
))
7377
}
7478

7579
fn get_eden_root(repo_root: &Path) -> Result<String> {
@@ -114,10 +118,15 @@ async fn get_status_internal(repo_root: &Path) -> Result<GetScmStatusResult> {
114118
}
115119

116120
async fn maybe_status_fastpath_internal(
117-
repo_root: &Path,
121+
repo_dot_path: &Path,
118122
io: &IO,
119123
list_ignored: bool,
120124
) -> Result<(status::Status, HashMap<RepoPathBuf, RepoPathBuf>)> {
125+
let repo_root = match repo_dot_path.parent() {
126+
Some(p) => p,
127+
None => bail!("invalid dot dir {}", repo_dot_path.display()),
128+
};
129+
121130
let eden_root = get_eden_root(repo_root).map_err(|_| OperationNotSupported)?;
122131

123132
let transport = get_socket_transport(repo_root)
@@ -137,8 +146,7 @@ async fn maybe_status_fastpath_internal(
137146
// the wrapper here and default to the Python implementation. D9025269 has a prototype
138147
// implementation of 'morestatus' in Rust, but we should gradually rewrite Mercurial in-place
139148
// and call out to it here rather than maintain a parallel implementation in the wrapper.
140-
let hg_dir = repo_root.join(".hg");
141-
if needs_morestatus_extension(&hg_dir, &dirstate_data.p2) {
149+
if needs_morestatus_extension(repo_dot_path, &dirstate_data.p2) {
142150
return Err(OperationNotSupported.into());
143151
}
144152

@@ -461,7 +469,8 @@ impl DirstateReader {
461469
}
462470

463471
fn read_hg_dirstate(repo_root: &Path) -> Result<DirstateData> {
464-
let dirstate = repo_root.join(".hg").join("dirstate");
472+
let ident = identity::must_sniff_dir(repo_root)?;
473+
let dirstate = repo_root.join(ident.dot_dir()).join("dirstate");
465474
let mut reader = DirstateReader {
466475
reader: BufReader::new(File::open(dirstate)?),
467476
sha256: Sha256::new(),

eden/scm/lib/hgcommands/src/commands/debug/segmentclone.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ pub fn run(opts: StatusOpts, _io: &IO, config: &mut ConfigSet) -> Result<u8> {
6262
}
6363
.context("error cloning segmented changelog")?;
6464

65-
let namedag_path = IndexedLogNameDagPath(destination.join(".hg/store/segments/v1"));
65+
let ident = identity::sniff_env();
66+
let dot_path = destination.join(ident.dot_dir());
67+
let namedag_path = IndexedLogNameDagPath(dot_path.join("store/segments/v1"));
6668
let mut namedag = namedag_path
6769
.open()
6870
.context("error opening segmented changelog")?;
@@ -92,14 +94,14 @@ pub fn run(opts: StatusOpts, _io: &IO, config: &mut ConfigSet) -> Result<u8> {
9294
block_on(namedag.flush(&heads)).context("error writing segmented changelog to disk")?;
9395

9496
fs::write(
95-
destination.join(".hg/store/remotenames"),
97+
dot_path.join("store/remotenames"),
9698
format!("{} bookmarks remote/master\n", master.to_hex()).as_bytes(),
9799
)
98100
.context("error writing to remotenames")?;
99101
}
100102

101103
fs::write(
102-
destination.join(".hg/requires"),
104+
dot_path.join("requires"),
103105
b"dotencode\n\
104106
fncache\n\
105107
generaldelta\n\
@@ -110,15 +112,15 @@ pub fn run(opts: StatusOpts, _io: &IO, config: &mut ConfigSet) -> Result<u8> {
110112
.context("error writing to hg requires")?;
111113

112114
fs::write(
113-
destination.join(".hg/store/requires"),
115+
dot_path.join("store/requires"),
114116
b"lazychangelog\n\
115117
narrowheads\n\
116118
visibleheads\n",
117119
)
118120
.context("error writing to hg store requires")?;
119121

120122
fs::write(
121-
destination.join(".hg/hgrc"),
123+
dot_path.join("hgrc"),
122124
format!(
123125
"[paths]\n\
124126
default = ssh://hg.vip.facebook.com//data/scm/{0}\n\

eden/scm/lib/hgcommands/src/commands/status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub fn run(opts: StatusOpts, io: &IO, repo: &mut Repo) -> Result<u8> {
153153
{
154154
// Attempt to fetch status information from EdenFS.
155155
let (status, copymap) = edenfs_client::status::maybe_status_fastpath(
156-
repo.path(),
156+
repo.dot_hg_path(),
157157
io,
158158
print_config.status_types.ignored,
159159
)

eden/scm/lib/workingcopy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ configmodel = { version = "0.1.0", path = "../configmodel" }
1212
crossbeam = "0.8"
1313
edenfs_client = { version = "0.1.0", path = "../edenfs-client", optional = true }
1414
futures = { version = "0.3.13", features = ["async-await", "compat"] }
15+
identity = { version = "0.1.0", path = "../identity" }
1516
manifest = { version = "0.1.0", path = "../manifest" }
1617
manifest-tree = { version = "0.1.0", path = "../manifest-tree" }
1718
parking_lot = { version = "0.11.2", features = ["send_guard"] }

eden/scm/lib/workingcopy/src/watchmanfs/watchmanfs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ impl WatchmanFileSystem {
5858
.resolve_root(CanonicalPath::canonicalize(self.vfs.root())?)
5959
.await?;
6060

61+
let ident = identity::must_sniff_dir(self.vfs.root())?;
6162
let excludes = Expr::Any(vec![Expr::DirName(DirNameTerm {
62-
path: PathBuf::from(".hg"),
63+
path: PathBuf::from(ident.dot_dir()),
6364
depth: None,
6465
})]);
6566

0 commit comments

Comments
 (0)