Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff foreach takes too long, causing performance bottleneck #1125

Open
lazhenyi opened this issue Feb 16, 2025 · 0 comments
Open

Diff foreach takes too long, causing performance bottleneck #1125

lazhenyi opened this issue Feb 16, 2025 · 0 comments

Comments

@lazhenyi
Copy link

lazhenyi commented Feb 16, 2025

Hi, this is my code:

let mut commits = vec![];
while let Ok(parent) = commit.parent(0) {
    if let Ok(now) = commit.tree() {
        if let Ok(pre) = parent.tree() {
            if let Ok(diff) = self.repository.diff_tree_to_tree(
                Some(&tree),
                Some(&parent.tree().unwrap()),
                Some(&mut DiffOptions::new())
            ){
                let mut deltas = vec![];
                diff.foreach(&mut |delta, _ | {
                    deltas.push(PathBuf::from(delta.new_file().path().unwrap_or(PathBuf::new().as_path())));
                    true
                },None, None,None);
                commits.push((Commit {
                    id: commit.id().to_string(),
                    msg: commit.message().unwrap_or("").to_string(),
                    time: chrono::DateTime::from_timestamp(commit.time().seconds(),0).unwrap().to_rfc2822(),
                    author: commit.author().name().unwrap_or("").to_string(),
                    email: commit.author().email().unwrap_or("").to_string(),
                },deltas));
                
            }
        }
    }
    commit = parent;
}

The average execution time is about two minutes, and I don't know how to improve it.
I would be grateful if there is any solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant