Skip to content

Commit b31c991

Browse files
simpkinsfacebook-github-bot
authored andcommitted
update the hg status fast-path to print errors reported by EdenFS
Summary: Update `hg status` to print errors that were returned by EdenFS's getScmStatusV2() call, and to exit unsuccessfully if there were any errors. Previously errors were silently ignored. Reviewed By: quark-zju Differential Revision: D19958503 fbshipit-source-id: cb3109df40eb86a5bf7e3818ddfb8da74d670405
1 parent ba42390 commit b31c991

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

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

+59-8
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn maybe_status_fastpath_internal(
131131

132132
let relativizer = PathRelativizer::new(cwd, repo_root);
133133
let relativizer = HgStatusPathRelativizer::new(print_config.root_relative, relativizer);
134-
print_config.print_status(
134+
let return_code = print_config.print_status(
135135
&repo_root,
136136
&status.status,
137137
&dirstate_data,
@@ -184,7 +184,7 @@ Your running Eden server is more than 45 days old. You should run
184184
}
185185
}
186186

187-
Ok(0)
187+
Ok(return_code)
188188
}
189189

190190
const NULL_COMMIT: [u8; 20] = [0; 20];
@@ -426,7 +426,7 @@ impl PrintConfig {
426426
relativizer: &HgStatusPathRelativizer,
427427
use_color: bool,
428428
io: &mut IO,
429-
) -> Result<()> {
429+
) -> Result<u8> {
430430
let groups = group_entries(&repo_root, &status, &dirstate_data)?;
431431
let endl = self.endl;
432432

@@ -503,7 +503,21 @@ impl PrintConfig {
503503
&groups.ignored,
504504
)?;
505505
print_group(PrintGroup::Clean, self.status_types.clean, &groups.clean)?;
506-
return Ok(());
506+
507+
if status.errors.is_empty() {
508+
Ok(0)
509+
} else {
510+
io.write_err("Encountered errors computing status for some paths:\n")?;
511+
for (path_str, error) in &status.errors {
512+
let path = Path::new(str::from_utf8(path_str)?);
513+
io.write_err(format!(
514+
" {}: {}\n",
515+
&relativizer.relativize(&path.to_path_buf()).display(),
516+
error,
517+
))?;
518+
}
519+
Ok(1)
520+
}
507521
}
508522
}
509523

@@ -802,11 +816,13 @@ mod test {
802816
p1: [u8; 20],
803817
p2: [u8; 20],
804818
entries: BTreeMap<Vec<u8>, ScmFileStatus>,
819+
errors: BTreeMap<Vec<u8>, String>,
805820
dirstate_data_tuples: HashMap<PathBuf, DirstateDataTuple>,
806821
files: Vec<(&'a str, Fixture<'a>)>,
807822
use_color: bool,
808823
stdout: String,
809824
stderr: String,
825+
return_code: u8,
810826
}
811827

812828
/// This function is used to drive most of the tests. It runs PrintConfig.print_status(), so it
@@ -831,7 +847,7 @@ mod test {
831847
};
832848
let status = ScmStatus {
833849
entries: test_case.entries,
834-
..Default::default()
850+
errors: test_case.errors,
835851
};
836852

837853
let relativizer = HgStatusPathRelativizer::new(
@@ -842,16 +858,16 @@ mod test {
842858
let tout = Vec::new();
843859
let terr = Vec::new();
844860
let mut io = IO::new(tin, tout, Some(terr));
845-
assert!(print_config
861+
let return_code = print_config
846862
.print_status(
847863
repo_root.path(),
848864
&status,
849865
&dirstate_data,
850866
&relativizer,
851867
test_case.use_color,
852-
&mut io
868+
&mut io,
853869
)
854-
.is_ok());
870+
.unwrap();
855871
let actual_output = io.output.as_any().downcast_ref::<Vec<u8>>().unwrap();
856872
assert_eq!(str::from_utf8(actual_output).unwrap(), test_case.stdout);
857873
let actual_error = io
@@ -862,6 +878,7 @@ mod test {
862878
.downcast_ref::<Vec<u8>>()
863879
.unwrap();
864880
assert_eq!(str::from_utf8(actual_error).unwrap(), test_case.stderr);
881+
assert_eq!(return_code, test_case.return_code);
865882
}
866883

867884
fn one_modified_file() -> BTreeMap<Vec<u8>, ScmFileStatus> {
@@ -1087,4 +1104,38 @@ I ignored.txt
10871104
&p2
10881105
));
10891106
}
1107+
1108+
#[test]
1109+
fn status_with_errors() {
1110+
let mut entries = BTreeMap::new();
1111+
entries.insert("unknown.txt".into(), ScmFileStatus::ADDED);
1112+
entries.insert("modified.txt".into(), ScmFileStatus::MODIFIED);
1113+
1114+
let mut errors = BTreeMap::new();
1115+
errors.insert(
1116+
"src/lib".into(),
1117+
"unable to fetch directory data: connection reset".into(),
1118+
);
1119+
1120+
let color_stdout = concat!(
1121+
"\u{001B}[34m\u{001B}[1mM modified.txt\u{001B}[0m\n",
1122+
"\u{001B}[35m\u{001B}[1m\u{001b}[4m? unknown.txt\u{001B}[0m\n",
1123+
);
1124+
let src_lib_path = Path::new("src").join("lib");
1125+
let stderr = format!(
1126+
"{}\n {}: {}\n",
1127+
"Encountered errors computing status for some paths:",
1128+
src_lib_path.display(),
1129+
"unable to fetch directory data: connection reset",
1130+
);
1131+
test_status(StatusTestCase {
1132+
entries,
1133+
errors,
1134+
use_color: true,
1135+
stdout: color_stdout.to_string(),
1136+
stderr: stderr.to_string(),
1137+
return_code: 1,
1138+
..Default::default()
1139+
});
1140+
}
10901141
}

0 commit comments

Comments
 (0)