Skip to content

Commit d6d59f3

Browse files
author
Stephan Dilly
committed
improve files in diff speed (#976)
1 parent 0360bdf commit d6d59f3

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Diff for: asyncgit/src/sync/commit_files.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{stash::is_stash_commit, utils::repo, CommitId};
44
use crate::{
55
error::Error, error::Result, StatusItem, StatusItemType,
66
};
7-
use git2::{Diff, DiffDelta, DiffOptions, Repository};
7+
use git2::{Diff, DiffOptions, Repository};
88
use scopetime::scope_time;
99

1010
/// get all files that are part of a commit
@@ -23,24 +23,30 @@ pub fn get_commit_files(
2323
get_commit_diff(&repo, id, None)?
2424
};
2525

26-
let mut res = Vec::new();
26+
let deltas = {
27+
scope_time!("get_commit_files.delta-count");
28+
diff.deltas().count()
29+
};
30+
31+
log::debug!("deltas in diff: {}", deltas);
32+
33+
let mut res = Vec::with_capacity(deltas);
34+
35+
{
36+
scope_time!("get_commit_files.diff-foreach");
37+
for delta in diff.deltas() {
38+
let status = StatusItemType::from(delta.status());
2739

28-
diff.foreach(
29-
&mut |delta: DiffDelta<'_>, _progress| {
3040
res.push(StatusItem {
3141
path: delta
3242
.new_file()
3343
.path()
3444
.map(|p| p.to_str().unwrap_or("").to_string())
3545
.unwrap_or_default(),
36-
status: StatusItemType::from(delta.status()),
46+
status,
3747
});
38-
true
39-
},
40-
None,
41-
None,
42-
None,
43-
)?;
48+
}
49+
}
4450

4551
Ok(res)
4652
}
@@ -51,7 +57,7 @@ pub fn get_compare_commits_diff(
5157
ids: (CommitId, CommitId),
5258
pathspec: Option<String>,
5359
) -> Result<Diff<'_>> {
54-
// scope_time!("get_compare_commits_diff");
60+
scope_time!("get_compare_commits_diff");
5561

5662
let commits = (
5763
repo.find_commit(ids.0.into())?,
@@ -89,7 +95,7 @@ pub(crate) fn get_commit_diff(
8995
id: CommitId,
9096
pathspec: Option<String>,
9197
) -> Result<Diff<'_>> {
92-
// scope_time!("get_commit_diff");
98+
scope_time!("get_commit_diff");
9399

94100
let commit = repo.find_commit(id.into())?;
95101
let commit_tree = commit.tree()?;

0 commit comments

Comments
 (0)