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

Integrate new hunk dependency algorithm #5252

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mtsgrd
Copy link
Contributor

@mtsgrd mtsgrd commented Oct 21, 2024

No description provided.

Copy link

vercel bot commented Oct 21, 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 Oct 22, 2024 2:28pm


impl InputDiff {
pub fn net_lines(&self) -> i32 {
self.new_lines as i32 - self.old_lines as i32
Copy link
Member

Choose a reason for hiding this comment

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

You can use the do different kinds of subtraction as a method on the new_lines, and you wont have to cast.
You probably wanna do the 'checked' kind though, which returns an Option.

Seems like net_lines is called from add_new which is called from add, which returns a Result.
So you can do something like

        self.net_lines()
            .checked_sub_unsigned(self.old_lines)
            .ok_or(anyhow!("Overflowed computing net lines"))

and do the ? operator. It's gonna be so much easier to debug in the future

.collect::<HashSet<_>>();

Ok(WorkspaceRanges {
paths: HashMap::from_iter(
Copy link
Member

Choose a reason for hiding this comment

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

You can skip from_iter and have the compiler infer the type like this

paths: paths
                .iter()
                .map(|path| (path.clone(), combine_path_ranges(path, &stacks)))
                .collect(),
                ```

use crate::{diff::InputDiff, hunk::HunkRange, stack::StackRanges};

#[derive(Debug, Default, PartialEq, Clone)]
pub struct WorkspaceRanges {
Copy link
Member

Choose a reason for hiding this comment

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

Kinda related to our IRL conversation earlier... so there is this convention to no "stutter" in names - this is module workspace, name WorkspaceRanges.
So if you want your API to be consumed as a hierarchy, it would be idiomatic to have workspace::Ranges at the consumption side.
I tend to prefer a flatter structure - exporting these types in the root level, and in that case I need the name would be WorkspaceRanges to be descriptive.
This is doing both which is suboptimal. Can rename later but trying to help shape the thinking here a bit

}
let paths = stacks
.iter()
.flat_map(|stack| stack.unique_paths())
Copy link
Member

Choose a reason for hiding this comment

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

You can write these like .flat_map(StackRanges::unique_paths) as well

@@ -0,0 +1,6 @@
pub mod diff;
Copy link
Member

Choose a reason for hiding this comment

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

There is still quite a bit of panic-y access by index. You can see it by adding this clippy rule at the top of the file

#![warn(clippy::indexing_slicing)]

While annoying to replace now, it will pay dividends if/when we hit stuff to debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants