-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude big files when performing a worktree diff.
This was lost previously when switching it over to a read-only implementation. Implementing it with an ignore list will take time, 400ms in the GitLab repository, but it's not slower than it was before and it is always preferred to not dump objects into the ODB unnecessarily.
- Loading branch information
Showing
8 changed files
with
69 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,3 +98,6 @@ impl CommandContext { | |
)?) | ||
} | ||
} | ||
|
||
mod repository_ext; | ||
pub use repository_ext::RepositoryExtLite; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use anyhow::{Context, Result}; | ||
use gix::bstr::{BString, ByteVec}; | ||
use tracing::instrument; | ||
|
||
/// An extension trait that should avoid pulling in large amounts of dependency so it can be used | ||
/// in more places without causing cycles. | ||
/// `gitbutler_repo::RepositoryExt` may not be usable everywhere due to that. | ||
pub trait RepositoryExtLite { | ||
/// Exclude files that are larger than `limit_in_bytes` (eg. database.sql which may never be intended to be committed) | ||
/// so they don't show up in the next diff. | ||
fn ignore_large_files_in_diffs(&self, limit_in_bytes: u64) -> Result<()>; | ||
} | ||
|
||
impl RepositoryExtLite for git2::Repository { | ||
#[instrument(level = tracing::Level::DEBUG, skip(self), err(Debug))] | ||
fn ignore_large_files_in_diffs(&self, limit_in_bytes: u64) -> Result<()> { | ||
use gix::bstr::ByteSlice; | ||
let repo = gix::open(self.path())?; | ||
let worktree_dir = repo | ||
.work_dir() | ||
.context("All repos are expected to have a worktree")?; | ||
let files_to_exclude: Vec<_> = repo | ||
.dirwalk_iter( | ||
repo.index_or_empty()?, | ||
None::<BString>, | ||
Default::default(), | ||
repo.dirwalk_options()? | ||
.emit_ignored(None) | ||
.emit_pruned(false) | ||
.emit_untracked(gix::dir::walk::EmissionMode::Matching), | ||
)? | ||
.filter_map(Result::ok) | ||
.filter_map(|item| { | ||
let path = worktree_dir.join(gix::path::from_bstr(item.entry.rela_path.as_bstr())); | ||
let file_is_too_large = path | ||
.metadata() | ||
.map_or(false, |md| md.is_file() && md.len() > limit_in_bytes); | ||
file_is_too_large | ||
.then(|| Vec::from(item.entry.rela_path).into_string().ok()) | ||
.flatten() | ||
}) | ||
.collect(); | ||
// TODO(ST): refactor this to be path-safe and ' ' save - the returned list is space separated (!!) | ||
// Just make sure this isn't needed anymore. | ||
let ignore_list = files_to_exclude.join(" "); | ||
// In-memory, libgit2 internal ignore rule | ||
self.add_ignore_rule(&ignore_list)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters