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

Use hunk dependency code for computing inter-commit dependencies #5393

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mtsgrd
Copy link
Contributor

@mtsgrd mtsgrd commented Nov 1, 2024

Implementation for computing dependencies and inverse dependencies between commits.

@estib-vega:
The scope of this PR escalated a bit.
Through implementing this extra functionality we discovered a couple of bugs with the new dependency calculation algorithm.
This PR reimplements parts of it to account for different (less frequent but possible) use-cases and tests to ensure that that works.

Changes

  • Add integration tests for dependency calculation (inter commit and diffs to commit)
  • Refactor the dependency calculation algo to account for use-cases like file deletion, recreation, lines added at the top, etc.

Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 11, 2024 9:48am

@github-actions github-actions bot added the rust Pull requests that update Rust code label Nov 1, 2024
Comment on lines 58 to 60
data.into_iter()
.fold(HashMap::new(), |mut acc, (commit_id, dependencies)| {
acc.entry(*commit_id)
.and_modify(|existing_dependencies| existing_dependencies.extend(dependencies))
.or_insert(dependencies.clone());
acc
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed, we declared the data variable for debugging, so we can drop that, skip the .collect_vec() and just return the concatenated the iter steps.

@estib-vega
Copy link
Contributor

@mtsgrd Since your changes I've done a couple of things:

1. We iterate over all files and commits when calculating the dependency graphs.

Before, we would only iterate over files that were present both in commits and in uncommitted changes because we were only interested on where the uncommitted files belonged.
Since we now are also interested on which commits depend on which, we need to traverse everything in the uncommitted files and stack commits.

2. I added a third hash-map that maps commit IDs to uncommitted hunks that depend on it

This enables to quickly check if a commit can't be moved because uncommitted hunks depend on it

3. Stack and Commits track dependency information

Every time we call get_applied_status_cached, we'll calculate the dependency information and store it to each Stack respectively.
The Stack should be considered the source of truth.
This information is then propagated to the VirtualBranchCommit for the Front-End to access.

Missing: Tests

I'll start adding some tests

@estib-vega estib-vega force-pushed the commit-dependencies branch 2 times, most recently from b133fd9 to bf254b6 Compare November 4, 2024 11:55
@estib-vega estib-vega force-pushed the commit-dependencies branch 2 times, most recently from caf4c28 to e222389 Compare November 4, 2024 11:58
@estib-vega estib-vega mentioned this pull request Nov 5, 2024
@estib-vega estib-vega marked this pull request as ready for review November 7, 2024 10:59
@estib-vega estib-vega force-pushed the commit-dependencies branch 2 times, most recently from d9ebc9f to dc53da3 Compare November 7, 2024 11:06
mtsgrd and others added 8 commits November 11, 2024 08:59
Move fully to the new Hunk Locking algorithm, remove the references to that flag and the settings UI
Stack keeps a map of commit and uncommitted chanegs inter-dependencies
Propagate information about commit and uncommited change inter-dependencies to the commits for the FE to access
Re-implement the algorithm so that it takes account of different scenarios when comparing input diffs.
Those changes include:
- Awareness of change type 
- Detection of "special" diffs, like file deletion and file recreation
- Correctly calculate the commit dependency graph between commits

Also add and update unit and integration tests
Track what's the index of:
- The next hunk range to visit
- The index of the the first hunk range to shift after adding an incoming hunk.

Also, calculate correctly the lines of the hunk ranges that are trimmed at the top in the following cases:
- Incomming hunk is only deleting lines
- Incomming hunk is only adding lines

Add special handling for intersections with hunks that only add lines
Add some high-level docs on the way the dependency graph is calculated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@gitbutler/desktop rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants