Skip to content

Commit

Permalink
Fix log crashing in subdirectories
Browse files Browse the repository at this point in the history
Replace `gix::open` by `gix::discover`. `gix::open` errors when the
passed directory is not a git repository.
  • Loading branch information
cruessler committed Jul 23, 2024
1 parent 0cb5b78 commit b51dd0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions asyncgit/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub enum Error {
Sign(#[from] crate::sync::sign::SignError),

///
#[error("gix::open error: {0}")]
GixOpen(#[from] Box<gix::open::Error>),
#[error("gix::discover error: {0}")]
GixDiscover(#[from] Box<gix::discover::Error>),

///
#[error("gix::reference::find::existing error: {0}")]
Expand Down Expand Up @@ -139,8 +139,8 @@ impl<T> From<crossbeam_channel::SendError<T>> for Error {
}
}

impl From<gix::open::Error> for Error {
fn from(error: gix::open::Error) -> Self {
Self::GixOpen(Box::new(error))
impl From<gix::discover::Error> for Error {
fn from(error: gix::discover::Error) -> Self {
Self::GixDiscover(Box::new(error))
}
}
2 changes: 1 addition & 1 deletion asyncgit/src/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl AsyncLog {
let mut entries = vec![CommitId::default(); LIMIT_COUNT];
entries.resize(0, CommitId::default());

let mut repo = gix::open(repo_path.gitpath())?;
let mut repo = gix::discover(repo_path.gitpath())?;
let mut walker =
LogWalkerWithoutFilter::new(&mut repo, LIMIT_COUNT)?;

Expand Down
4 changes: 2 additions & 2 deletions asyncgit/src/sync/logwalker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'a> LogWalker<'a> {
///
/// `SharedCommitFilterFn` requires access to a `git2::repo::Repository` because, under the hood,
/// it calls into functions that work with a `git2::repo::Repository`. It seems unwise to open a
/// repo both through `gix::open` and `Repository::open_ext` at the same time, so there is a
/// repo both through `gix::discover` and `Repository::open_ext` at the same time, so there is a
/// separate struct that works with `gix::Repository` only.
///
/// A more long-term option is to refactor filtering to work with a `gix::Repository` and to remove
Expand Down Expand Up @@ -271,7 +271,7 @@ mod tests {
stage_add_file(repo_path, file_path).unwrap();
let oid2 = commit(repo_path, "commit2").unwrap();

let mut repo = gix::open(repo_path.gitpath()).unwrap();
let mut repo = gix::discover(repo_path.gitpath()).unwrap();
let mut walk = LogWalkerWithoutFilter::new(&mut repo, 100)?;
let mut items = Vec::new();
assert!(matches!(walk.read(&mut items), Ok(2)));
Expand Down

0 comments on commit b51dd0f

Please sign in to comment.