Get performance metrics for get_wd_tree()

It's a tiny little function, but I think it can be slow
as it could incur a lot of work, scaling up with the size
of the repository, and the amount of untracked data in it.

Let's gather some data.
This commit is contained in:
Sebastian Thiel 2024-05-29 06:48:49 +02:00
parent ea219eedf9
commit 407ec1427b
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
3 changed files with 5 additions and 3 deletions

View File

@ -38,7 +38,7 @@ mod url;
pub use self::url::*;
mod repository_ext;
pub use repository_ext::*;
pub use repository_ext::RepositoryExt;
mod tree_ext;
pub use tree_ext::*;

View File

@ -1,14 +1,17 @@
use anyhow::Result;
use git2::{Repository, Tree};
use tracing::instrument;
/// Extension trait for `git2::Repository`.
///
/// For now, it collects useful methods from `gitbutler-core::git::Repository`
pub trait RepositoryExt {
/// Based on the index, add all data similar to `git add .` and create a tree from it, which is returned.
fn get_wd_tree(&self) -> Result<Tree>;
}
impl RepositoryExt for Repository {
#[instrument(level = tracing::Level::DEBUG, skip(self), err(Debug))]
fn get_wd_tree(&self) -> Result<Tree> {
let mut index = self.index()?;
index.add_all(["*"], git2::IndexAddOption::DEFAULT, None)?;

View File

@ -615,8 +615,7 @@ impl Repository {
}
pub fn repo(&self) -> &git2::Repository {
let r = &self.git_repository;
r.into()
(&self.git_repository).into()
}
}