Skip to content

Commit ae0e8b3

Browse files
author
Kiril Videlov
committed
refactor: remove hunk_locks field from HunkAssignment and all usages
1 parent bfd2314 commit ae0e8b3

10 files changed

Lines changed: 5 additions & 107 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/but-hunk-assignment/src/lib.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use anyhow::Result;
1818
use bstr::{BString, ByteSlice};
1919
use but_core::{DiffSpec, HunkHeader, TreeChange, UnifiedPatch, ref_metadata::StackId};
2020
use but_db::{HunkAssignmentsHandle, HunkAssignmentsHandleMut};
21-
use but_hunk_dependency::ui::{HunkDependencies, HunkLock};
21+
use but_hunk_dependency::ui::HunkDependencies;
2222
use gix::ObjectId;
2323
use reconcile::MultipleOverlapping;
2424
use serde::{Deserialize, Serialize};
@@ -59,10 +59,6 @@ pub struct HunkAssignment {
5959
schemars(schema_with = "but_schemars::stack_id_opt")
6060
)]
6161
pub stack_id: Option<StackId>,
62-
/// The dependencies(locks) that this hunk has. This determines where the hunk can be assigned.
63-
/// This field is ignored when HunkAssignment is passed by the UI to create a new assignment.
64-
#[serde(skip)]
65-
pub hunk_locks: Option<Vec<HunkLock>>,
6662
/// The line numbers that were added in this hunk.
6763
pub line_nums_added: Option<Vec<usize>>,
6864
/// The line numbers that were removed in this hunk.
@@ -98,7 +94,6 @@ impl TryFrom<but_db::HunkAssignment> for HunkAssignment {
9894
path: value.path,
9995
path_bytes: value.path_bytes.into(),
10096
stack_id,
101-
hunk_locks: None,
10297
line_nums_added: None, // derived data (not persisted)
10398
line_nums_removed: None, // derived data (not persisted)
10499
diff: None, // derived data (not persisted)
@@ -518,7 +513,6 @@ fn diff_to_assignments(diff: Option<UnifiedPatch>, path: BString) -> Vec<HunkAss
518513
path: path_str.into(),
519514
path_bytes: path,
520515
stack_id: None,
521-
hunk_locks: None,
522516
line_nums_added: None,
523517
line_nums_removed: None,
524518
diff: None,
@@ -529,7 +523,6 @@ fn diff_to_assignments(diff: Option<UnifiedPatch>, path: BString) -> Vec<HunkAss
529523
path: path_str.into(),
530524
path_bytes: path,
531525
stack_id: None,
532-
hunk_locks: None,
533526
line_nums_added: None,
534527
line_nums_removed: None,
535528
diff: None,
@@ -547,7 +540,6 @@ fn diff_to_assignments(diff: Option<UnifiedPatch>, path: BString) -> Vec<HunkAss
547540
path: path_str.into(),
548541
path_bytes: path,
549542
stack_id: None,
550-
hunk_locks: None,
551543
line_nums_added: None,
552544
line_nums_removed: None,
553545
diff: None,
@@ -564,7 +556,6 @@ fn diff_to_assignments(diff: Option<UnifiedPatch>, path: BString) -> Vec<HunkAss
564556
path: path_str.clone().into(),
565557
path_bytes: path.clone(),
566558
stack_id: None,
567-
hunk_locks: None,
568559
line_nums_added: Some(line_nums_added_new),
569560
line_nums_removed: Some(line_nums_removed_old),
570561
diff: Some(hunk.diff.clone()),
@@ -581,7 +572,6 @@ fn diff_to_assignments(diff: Option<UnifiedPatch>, path: BString) -> Vec<HunkAss
581572
path: path_str.into(),
582573
path_bytes: path.clone(),
583574
stack_id: None,
584-
hunk_locks: None,
585575
line_nums_added: None,
586576
line_nums_removed: None,
587577
diff: None,
@@ -641,7 +631,6 @@ fn requests_to_assignments(request: Vec<HunkAssignmentRequest>) -> Vec<HunkAssig
641631
path: req.path_bytes.to_str_lossy().into(),
642632
path_bytes: req.path_bytes,
643633
stack_id: req.stack_id,
644-
hunk_locks: None,
645634
line_nums_added: None,
646635
line_nums_removed: None,
647636
diff: None,
@@ -751,7 +740,6 @@ mod tests {
751740
path: path.to_string(),
752741
path_bytes: BString::from(path),
753742
stack_id: stack_id.map(stack_id_seq),
754-
hunk_locks: None,
755743
line_nums_added: None,
756744
line_nums_removed: None,
757745
diff: None,
@@ -794,7 +782,6 @@ mod tests {
794782
&& a.path == b.path
795783
&& a.path_bytes == b.path_bytes
796784
&& a.stack_id == b.stack_id
797-
&& a.hunk_locks == b.hunk_locks
798785
}
799786
fn assert_eq(a: Vec<HunkAssignment>, b: Vec<HunkAssignment>) {
800787
assert!(
@@ -963,7 +950,6 @@ mod tests {
963950
path: "image.png".to_string(),
964951
path_bytes: BString::from("image.png"),
965952
stack_id: Some(stack_id_seq(1)),
966-
hunk_locks: None,
967953
line_nums_added: None,
968954
line_nums_removed: None,
969955
diff: None,
@@ -975,7 +961,6 @@ mod tests {
975961
path: "image.png".to_string(),
976962
path_bytes: BString::from("image.png"),
977963
stack_id: None,
978-
hunk_locks: None,
979964
line_nums_added: None,
980965
line_nums_removed: None,
981966
diff: None,
@@ -1002,7 +987,6 @@ mod tests {
1002987
path: "file.txt".to_string(),
1003988
path_bytes: BString::from("file.txt"),
1004989
stack_id: None,
1005-
hunk_locks: None,
1006990
line_nums_added: None,
1007991
line_nums_removed: None,
1008992
diff: None,
@@ -1027,7 +1011,6 @@ mod tests {
10271011
path: "image1.png".to_string(),
10281012
path_bytes: BString::from("image1.png"),
10291013
stack_id: Some(stack_id_seq(1)),
1030-
hunk_locks: None,
10311014
line_nums_added: None,
10321015
line_nums_removed: None,
10331016
diff: None,
@@ -1039,7 +1022,6 @@ mod tests {
10391022
path: "image2.png".to_string(),
10401023
path_bytes: BString::from("image2.png"),
10411024
stack_id: None,
1042-
hunk_locks: None,
10431025
line_nums_added: None,
10441026
line_nums_removed: None,
10451027
diff: None,
@@ -1064,7 +1046,6 @@ mod tests {
10641046
path: "logo.png".to_string(),
10651047
path_bytes: BString::from("logo.png"),
10661048
stack_id: Some(stack_id_seq(1)),
1067-
hunk_locks: None,
10681049
line_nums_added: None,
10691050
line_nums_removed: None,
10701051
diff: None,
@@ -1081,7 +1062,6 @@ mod tests {
10811062
path: "logo.png".to_string(),
10821063
path_bytes: BString::from("logo.png"),
10831064
stack_id: None,
1084-
hunk_locks: None,
10851065
line_nums_added: None,
10861066
line_nums_removed: None,
10871067
diff: None,
@@ -1128,7 +1108,6 @@ mod tests {
11281108
path: "data.file".to_string(),
11291109
path_bytes: BString::from("data.file"),
11301110
stack_id: None,
1131-
hunk_locks: None,
11321111
line_nums_added: None,
11331112
line_nums_removed: None,
11341113
diff: None,

crates/but-hunk-assignment/src/reconcile.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ pub enum MultipleOverlapping {
1313

1414
impl HunkAssignment {
1515
fn set_from(&mut self, other: &Self, applied_stack_ids: &[StackId], update_unassigned: bool) {
16-
// Always override the locks with the from the other assignment
17-
self.hunk_locks = other.hunk_locks.clone();
1816
// Always set the path from the other assignment
1917
self.path = other.path.clone();
2018
// Override the id only if the other assignment has an id
@@ -68,13 +66,6 @@ pub(crate) fn assignments(
6866
match intersecting.len().cmp(&1) {
6967
Ordering::Less => {
7068
// No intersection - do nothing, the None assignment is kept
71-
let matching_file = old
72-
.iter()
73-
.filter(|current_entry| current_entry.path == new_assignment.path)
74-
.collect::<Vec<_>>();
75-
if let Some(matching_file) = matching_file.first() {
76-
new_assignment.hunk_locks = matching_file.hunk_locks.clone();
77-
}
7869
}
7970
Ordering::Equal => {
8071
new_assignment.set_from(intersecting[0], applied_stack_ids, update_unassigned);

crates/but-tools/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ test = false
1414
but-core.workspace = true
1515
but-workspace = { workspace = true, features = ["legacy"] }
1616
but-serde.workspace = true
17-
but-hunk-dependency.workspace = true
1817
but-hunk-assignment.workspace = true
1918
but-ctx = { workspace = true, features = ["legacy"] }
2019

crates/but-tools/src/workspace.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,6 @@ pub struct RichHunk {
13521352
pub diff: String,
13531353
/// The stack ID this hunk is assigned to, if any.
13541354
pub assigned_to_stack: Option<but_core::ref_metadata::StackId>,
1355-
/// The locks this hunk has, if any.
1356-
pub dependency_locks: Vec<but_hunk_dependency::ui::HunkLock>,
13571355
}
13581356

13591357
#[derive(Debug, Clone, serde::Serialize)]
@@ -1593,20 +1591,13 @@ fn get_file_changes(
15931591
.find(|a| {
15941592
a.path_bytes == change.path && a.hunk_header == Some(hunk.into())
15951593
})
1596-
.map(|a| (a.stack_id, a.hunk_locks.clone()));
1594+
.map(|a| a.stack_id);
15971595

1598-
let (assigned_to_stack, dependency_locks) =
1599-
if let Some((stack_id, locks)) = assignment {
1600-
let locks = locks.unwrap_or_default();
1601-
(stack_id, locks)
1602-
} else {
1603-
(None, vec![])
1604-
};
1596+
let assigned_to_stack = assignment.flatten();
16051597

16061598
RichHunk {
16071599
diff,
16081600
assigned_to_stack,
1609-
dependency_locks,
16101601
}
16111602
})
16121603
.collect::<Vec<_>>();

crates/but/src/command/commit/move.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ mod tests {
294294
path: "test.txt".to_string(),
295295
path_bytes: BString::from("test.txt"),
296296
stack_id: None,
297-
hunk_locks: None,
298297
line_nums_added: None,
299298
line_nums_removed: None,
300299
diff: None,

crates/but/src/command/legacy/commit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,6 @@ mod tests {
749749
path: path.to_owned(),
750750
path_bytes: path.as_bytes().into(),
751751
stack_id: None,
752-
hunk_locks: None,
753752
line_nums_added: None,
754753
line_nums_removed: None,
755754
diff: None,

crates/but/src/command/legacy/rub/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ mod tests {
11411141
path: "test.txt".to_string(),
11421142
path_bytes: BString::from("test.txt"),
11431143
stack_id: None,
1144-
hunk_locks: None,
11451144
line_nums_added: None,
11461145
line_nums_removed: None,
11471146
diff: None,

crates/but/src/command/legacy/status/mod.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
id::{SegmentWithId, ShortId, StackWithId, TreeChangeWithId},
2727
tui::text::truncate_text,
2828
utils::{
29-
OutputChannel, WriteWithUtils, shorten_hex_object_id, shorten_object_id, split_short_id,
29+
OutputChannel, WriteWithUtils, shorten_hex_object_id, shorten_object_id,
3030
time::format_relative_time_verbose,
3131
},
3232
};
@@ -755,45 +755,14 @@ fn print_assignments(
755755
"uncommitted file",
756756
)?;
757757

758-
let lock_items: Vec<(String, String)> = fa
759-
.assignments
760-
.iter()
761-
.flat_map(|a| a.inner.hunk_locks.iter())
762-
.flatten()
763-
.map(|l| l.commit_id.to_string())
764-
.collect::<std::collections::BTreeSet<_>>()
765-
.into_iter()
766-
.map(|commit_id| {
767-
let short_id = shorten_hex_object_id(repo, &commit_id);
768-
let (lead, rest) = split_short_id(&short_id, 2);
769-
(lead.to_string(), rest.to_string())
770-
})
771-
.collect();
772-
773-
let mut lock_spans: Vec<Span<'static>> = Vec::new();
774-
if !lock_items.is_empty() {
775-
lock_spans.push(Span::raw("🔒 "));
776-
for (i, (lead, rest)) in lock_items.into_iter().enumerate() {
777-
if i > 0 {
778-
lock_spans.push(Span::raw(", "));
779-
}
780-
lock_spans.push(Span::styled(lead, Style::default().blue().bold()));
781-
lock_spans.push(Span::styled(rest, Style::default().blue()));
782-
}
783-
}
784-
785-
let mut file_line = Vec::from([
758+
let file_line = Vec::from([
786759
Span::raw(id_padding.clone()),
787760
Span::styled(cli_id.to_string(), Style::default().bold().blue()),
788761
Span::raw(" "),
789762
Span::raw(status.to_string()),
790763
Span::raw(" "),
791764
path,
792765
]);
793-
if !lock_spans.is_empty() {
794-
file_line.push(Span::raw(" "));
795-
file_line.extend(lock_spans);
796-
}
797766

798767
if unstaged {
799768
output.unstaged_file(Vec::from([Span::raw("┊ ")]), file_line, file_cli_id)?;

0 commit comments

Comments
 (0)