Skip to content

Commit 8f9b714

Browse files
jdelliotfacebook-github-bot
authored andcommitted
Enable future caching of sl status calls by moving params to a single struct
Summary: # Context: We are working to refactor the EdenFs CLI client library into a supported XFN consumable library to avoid code duplication and sub-optimal usage patterns. # This Diff: We would like to cache the results of `sl status`, but that was a bit clunky with the number of params (and their future updates). Moved all params passed to the impl into a single, hashable struct. Also fixed the visibilty of other impl methods (they should all be private). # Facebook Leveraging the internal mocking framework for Commands: https://www.internalfb.com/code/fbsource/[e06cfadfd5c60f5aa51ff7e8af93837542d632d8]/fbcode/common/rust/async_process_traits/README.md. Reviewed By: lXXXw Differential Revision: D73063148 fbshipit-source-id: 68bb9c80ff3da9cd0d1cb550a203a290b8c94389
1 parent dcac4d9 commit 8f9b714

File tree

3 files changed

+56
-50
lines changed

3 files changed

+56
-50
lines changed

eden/fs/cli_rs/sapling-client/src/debug_diff_dirs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub async fn get_diff_dirs(
7070
.await
7171
}
7272

73-
pub async fn get_diff_dirs_impl<Spawner>(
73+
async fn get_diff_dirs_impl<Spawner>(
7474
spawner: &Spawner,
7575
first: &str,
7676
second: Option<&str>,

eden/fs/cli_rs/sapling-client/src/mergebase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ where
7171
get_mergebase_details_impl(&TokioCommandSpawner, current_dir, commit, mergegase_with).await
7272
}
7373

74-
pub async fn get_mergebase_details_impl<Spawner, D, C, M>(
74+
async fn get_mergebase_details_impl<Spawner, D, C, M>(
7575
spawner: &Spawner,
7676
current_dir: D,
7777
commit: C,

eden/fs/cli_rs/sapling-client/src/status.rs

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ pub enum SaplingGetStatusResult {
2929
TooManyChanges,
3030
}
3131

32+
#[derive(Clone, Debug, Hash, PartialEq)]
33+
struct GetStatusParams {
34+
first: String,
35+
second: Option<String>,
36+
limit_results: usize,
37+
case_insensitive_suffix_compares: bool,
38+
root: Option<PathBuf>,
39+
included_roots: Option<Vec<PathBuf>>,
40+
included_suffixes: Option<Vec<String>>,
41+
excluded_roots: Option<Vec<PathBuf>>,
42+
excluded_suffixes: Option<Vec<String>>,
43+
}
44+
3245
pub async fn get_status_with_includes(
3346
first: &str,
3447
second: Option<&str>,
@@ -66,42 +79,34 @@ pub async fn get_status(
6679
excluded_roots: &Option<Vec<PathBuf>>,
6780
excluded_suffixes: &Option<Vec<String>>,
6881
) -> Result<SaplingGetStatusResult> {
69-
get_status_impl(
70-
&TokioCommandSpawner,
71-
first,
72-
second,
82+
let params = GetStatusParams {
83+
first: first.to_string(),
84+
second: second.map(|s| s.to_string()),
7385
limit_results,
7486
case_insensitive_suffix_compares,
75-
root,
76-
included_roots,
77-
included_suffixes,
78-
excluded_roots,
79-
excluded_suffixes,
80-
)
81-
.await
87+
root: root.clone(),
88+
included_roots: included_roots.clone(),
89+
included_suffixes: included_suffixes.clone(),
90+
excluded_roots: excluded_roots.clone(),
91+
excluded_suffixes: excluded_suffixes.clone(),
92+
};
93+
94+
get_status_impl(&TokioCommandSpawner, params).await
8295
}
8396

84-
pub async fn get_status_impl<Spawner>(
97+
async fn get_status_impl<Spawner>(
8598
spawner: &Spawner,
86-
first: &str,
87-
second: Option<&str>,
88-
limit_results: usize,
89-
case_insensitive_suffix_compares: bool,
90-
root: &Option<PathBuf>,
91-
included_roots: &Option<Vec<PathBuf>>,
92-
included_suffixes: &Option<Vec<String>>,
93-
excluded_roots: &Option<Vec<PathBuf>>,
94-
excluded_suffixes: &Option<Vec<String>>,
99+
mut params: GetStatusParams,
95100
) -> Result<SaplingGetStatusResult>
96101
where
97102
Spawner: CommandSpawner,
98103
{
99-
let included_suffixes = included_suffixes.clone().map(|is| {
104+
params.included_suffixes = params.included_suffixes.clone().map(|is| {
100105
is.into_iter()
101106
.map(|s| {
102107
format!(
103108
".{}",
104-
if case_insensitive_suffix_compares {
109+
if params.case_insensitive_suffix_compares {
105110
s.to_ascii_lowercase()
106111
} else {
107112
s
@@ -110,12 +115,12 @@ where
110115
})
111116
.collect::<Vec<String>>()
112117
});
113-
let excluded_suffixes = excluded_suffixes.clone().map(|is| {
118+
params.excluded_suffixes = params.excluded_suffixes.clone().map(|is| {
114119
is.into_iter()
115120
.map(|s| {
116121
format!(
117122
".{}",
118-
if case_insensitive_suffix_compares {
123+
if params.case_insensitive_suffix_compares {
119124
s.to_ascii_lowercase()
120125
} else {
121126
s
@@ -125,14 +130,16 @@ where
125130
.collect::<Vec<String>>()
126131
});
127132

128-
let mut args = vec!["status", "-mardu", "--rev", first];
129-
if let Some(second) = second {
133+
let mut args = vec!["status", "-mardu", "--rev", &params.first];
134+
let second: String;
135+
if let Some(second_) = params.second {
136+
second = second_;
130137
args.push("--rev");
131-
args.push(second);
138+
args.push(&second);
132139
}
133140

134141
let root_path_arg: String;
135-
if let Some(root) = root {
142+
if let Some(root) = params.root {
136143
root_path_arg = format!("path:{}", root.display());
137144
args.push(&root_path_arg);
138145
};
@@ -153,14 +160,14 @@ where
153160
while let Some(line) = lines.next_line().await? {
154161
if let Some(status_line) = process_one_status_line(&line)? {
155162
if is_path_included(
156-
case_insensitive_suffix_compares,
163+
params.case_insensitive_suffix_compares,
157164
&status_line.1,
158-
included_roots,
159-
&included_suffixes,
160-
excluded_roots,
161-
&excluded_suffixes,
165+
&params.included_roots,
166+
&params.included_suffixes,
167+
&params.excluded_roots,
168+
&params.excluded_suffixes,
162169
) {
163-
if status.len() >= limit_results {
170+
if status.len() >= params.limit_results {
164171
return Ok(SaplingGetStatusResult::TooManyChanges);
165172
}
166173
status.push(status_line);
@@ -246,19 +253,18 @@ A fbcode/buck2/app/buck2_audit_server/src/perf/configured_graph_size.rs
246253
get_sapling_executable_path(),
247254
Some((0, Some(output.as_bytes().to_vec()))),
248255
);
249-
let result = get_status_impl(
250-
&spawner,
251-
FIRST_COMMIT_ID,
252-
Some(SECOND_COMMIT_ID),
253-
1000,
254-
false,
255-
&None,
256-
&None,
257-
&None,
258-
&None,
259-
&None,
260-
)
261-
.await?;
256+
let params = GetStatusParams {
257+
first: FIRST_COMMIT_ID.to_string(),
258+
second: Some(SECOND_COMMIT_ID.to_string()),
259+
limit_results: 1000,
260+
case_insensitive_suffix_compares: false,
261+
root: None,
262+
included_roots: None,
263+
included_suffixes: None,
264+
excluded_roots: None,
265+
excluded_suffixes: None,
266+
};
267+
let result = get_status_impl(&spawner, params).await?;
262268
let expected = SaplingGetStatusResult::Normal(vec![
263269
(
264270
SaplingStatus::Modified,

0 commit comments

Comments
 (0)