From f13e827e33637a09a155f4086022185d36a41b87 Mon Sep 17 00:00:00 2001 From: Caleb Owens Date: Mon, 6 May 2024 19:45:05 +0100 Subject: [PATCH] Don't reparse branch_id This should make the situation where an error occurs even more absurd. It should also be saving some extra work which is always a bonus --- crates/gitbutler-core/src/git/diff.rs | 4 +++- .../src/virtual_branches/virtual.rs | 15 ++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/gitbutler-core/src/git/diff.rs b/crates/gitbutler-core/src/git/diff.rs index 8a879026b..c5ead2903 100644 --- a/crates/gitbutler-core/src/git/diff.rs +++ b/crates/gitbutler-core/src/git/diff.rs @@ -9,6 +9,8 @@ use tracing::instrument; use super::Repository; use crate::git; +use crate::id::Id; +use crate::virtual_branches::Branch; pub type DiffByPathMap = HashMap; @@ -106,7 +108,7 @@ impl GitHunk { #[derive(Debug, PartialEq, Eq, Clone, Serialize, Copy)] #[serde(rename_all = "camelCase")] pub struct HunkLock { - pub branch_id: uuid::Uuid, + pub branch_id: Id, pub commit_id: git::Oid, } diff --git a/crates/gitbutler-core/src/virtual_branches/virtual.rs b/crates/gitbutler-core/src/virtual_branches/virtual.rs index ff5bd517c..e21c39e9b 100644 --- a/crates/gitbutler-core/src/virtual_branches/virtual.rs +++ b/crates/gitbutler-core/src/virtual_branches/virtual.rs @@ -25,7 +25,6 @@ use super::{ branch_to_remote_branch, errors, target, RemoteBranch, VirtualBranchesHandle, }; use crate::git::diff::{diff_files_into_hunks, trees, FileDiff}; -use crate::id::Id; use crate::virtual_branches::branch::HunkHash; use crate::{ askpass::AskpassBroker, @@ -1794,12 +1793,9 @@ fn get_applied_status( let commit_id = git::Oid::from(blame_hunk.orig_commit_id()); if commit_id != *target_sha && commit_id != *integration_commit { let hash = Hunk::hash_diff(&hunk.diff_lines); - let id = commit_to_branch.get(&commit_id).map(|id| id.to_string()); - let branch_id = if let Some(id) = id { - uuid::Uuid::parse_str(&id)? - } else { - // Log the error and continue - // TODO: Why does that happen? + let Some(branch_id) = commit_to_branch.get(&commit_id) else { + // This is a truly absurd situation + // TODO: Test if this still happens tracing::error!( "commit {:?} not found in commit_to_branch map {:?}", commit_id, @@ -1807,8 +1803,9 @@ fn get_applied_status( ); continue; }; + let hunk_lock = diff::HunkLock { - branch_id, + branch_id: *branch_id, commit_id, }; locked_hunk_map @@ -1924,7 +1921,7 @@ fn get_applied_status( let first_lock = &locks[0]; let p = virtual_branches .iter() - .position(|vb| vb.id == Id::::from(first_lock.branch_id)); + .position(|vb| vb.id == first_lock.branch_id); match p { Some(p) => p, _ => default_vbranch_pos,