|
|
@ -29,7 +29,7 @@ pub fn get_diff_base(file: &Path) -> Result<Vec<u8>> {
|
|
|
|
// TODO cache repository lookup
|
|
|
|
// TODO cache repository lookup
|
|
|
|
|
|
|
|
|
|
|
|
let repo_dir = file.parent().context("file has no parent directory")?;
|
|
|
|
let repo_dir = file.parent().context("file has no parent directory")?;
|
|
|
|
let repo = open_repo(repo_dir, None)
|
|
|
|
let repo = open_repo(repo_dir)
|
|
|
|
.context("failed to open git repo")?
|
|
|
|
.context("failed to open git repo")?
|
|
|
|
.to_thread_local();
|
|
|
|
.to_thread_local();
|
|
|
|
let head = repo.head_commit()?;
|
|
|
|
let head = repo.head_commit()?;
|
|
|
@ -57,7 +57,7 @@ pub fn get_current_head_name(file: &Path) -> Result<Arc<ArcSwap<Box<str>>>> {
|
|
|
|
debug_assert!(!file.exists() || file.is_file());
|
|
|
|
debug_assert!(!file.exists() || file.is_file());
|
|
|
|
debug_assert!(file.is_absolute());
|
|
|
|
debug_assert!(file.is_absolute());
|
|
|
|
let repo_dir = file.parent().context("file has no parent directory")?;
|
|
|
|
let repo_dir = file.parent().context("file has no parent directory")?;
|
|
|
|
let repo = open_repo(repo_dir, None)
|
|
|
|
let repo = open_repo(repo_dir)
|
|
|
|
.context("failed to open git repo")?
|
|
|
|
.context("failed to open git repo")?
|
|
|
|
.to_thread_local();
|
|
|
|
.to_thread_local();
|
|
|
|
let head_ref = repo.head_ref()?;
|
|
|
|
let head_ref = repo.head_ref()?;
|
|
|
@ -72,10 +72,10 @@ pub fn get_current_head_name(file: &Path) -> Result<Arc<ArcSwap<Box<str>>>> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn for_each_changed_file(cwd: &Path, f: impl Fn(Result<FileChange>) -> bool) -> Result<()> {
|
|
|
|
pub fn for_each_changed_file(cwd: &Path, f: impl Fn(Result<FileChange>) -> bool) -> Result<()> {
|
|
|
|
status(&open_repo(cwd, None)?.to_thread_local(), f)
|
|
|
|
status(&open_repo(cwd)?.to_thread_local(), f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn open_repo(path: &Path, ceiling_dir: Option<&Path>) -> Result<ThreadSafeRepository> {
|
|
|
|
fn open_repo(path: &Path) -> Result<ThreadSafeRepository> {
|
|
|
|
// custom open options
|
|
|
|
// custom open options
|
|
|
|
let mut git_open_opts_map = gix::sec::trust::Mapping::<gix::open::Options>::default();
|
|
|
|
let mut git_open_opts_map = gix::sec::trust::Mapping::<gix::open::Options>::default();
|
|
|
|
|
|
|
|
|
|
|
@ -104,9 +104,6 @@ fn open_repo(path: &Path, ceiling_dir: Option<&Path>) -> Result<ThreadSafeReposi
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let open_options = gix::discover::upwards::Options {
|
|
|
|
let open_options = gix::discover::upwards::Options {
|
|
|
|
ceiling_dirs: ceiling_dir
|
|
|
|
|
|
|
|
.map(|dir| vec![dir.to_owned()])
|
|
|
|
|
|
|
|
.unwrap_or_default(),
|
|
|
|
|
|
|
|
dot_git_only: true,
|
|
|
|
dot_git_only: true,
|
|
|
|
..Default::default()
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
};
|
|
|
|