Function broot::git::closest_repo_dir
source · Expand description
return the closest parent (or self) containing a .git file
Examples found in repository?
src/git/status_computer.rs (line 47)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
pub fn get_tree_status(root_path: &Path, dam: &mut Dam) -> ComputationResult<TreeGitStatus> {
match git::closest_repo_dir(root_path) {
None => ComputationResult::None,
Some(repo_path) => {
let comp = TS_CACHE_MX
.lock()
.unwrap()
.get(&repo_path)
.map(|c| (*c).clone());
match comp {
Some(Computation::Finished(comp_res)) => {
// already computed
comp_res
}
Some(Computation::InProgress(comp_receiver)) => {
// computation in progress
// We do a select! to wait for either the dam
// or the receiver
debug!("start select on in progress computation");
dam.select(comp_receiver)
}
None => {
// not yet started. We launch the computation and store
// the receiver immediately.
// We use the dam to return from this function when
// needed (while letting the underlying thread finish
// the job)
//
// note: must also update the TS_CACHE entry at end
let (s, r) = bounded(1);
TS_CACHE_MX
.lock()
.unwrap()
.insert(repo_path.clone(), Computation::InProgress(r));
dam.try_compute(move || {
let comp_res = compute_tree_status(&repo_path);
TS_CACHE_MX
.lock()
.unwrap()
.insert(repo_path.clone(), Computation::Finished(comp_res.clone()));
if let Err(e) = s.send(comp_res.clone()) {
debug!("error while sending comp result: {:?}", e);
}
comp_res
})
}
}
}
}
}