Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 58 additions & 55 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.dependencies]
bstr = "1.11.1"
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
gix = { git = "https://github.com/GitoxideLabs/gitoxide", rev = "7255a5fc0aa790b54e3176e8ecf066457acd9eef", default-features = false, features = [
gix = { git = "https://github.com/GitoxideLabs/gitoxide", rev = "cd96b6439d119c5189a8e7349d2e7e2533db41b5", default-features = false, features = [
] }
gix-testtools = "0.15.0"
insta = "1.41.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/but-cli/src/command/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn intersect_workspace_ranges(
let mut missed_hunks = Vec::new();
for change in worktree_changes {
let unidiff = change.unified_diff(repo, 0)?;
let but_core::UnifiedDiff::Patch { hunks } = unidiff else {
let but_core::UnifiedDiff::Patch { hunks, .. } = unidiff else {
continue;
};
let mut intersections = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/but-cli/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub(crate) fn discard_change(
change.path == path
&& change.previous_path() == previous_path.as_ref().map(|p| p.as_bstr())
}).with_context(|| format!("Couldn't find worktree change for file at '{path}' (previous-path: {previous_path:?}"))?;
let UnifiedDiff::Patch { hunks } =
let UnifiedDiff::Patch { hunks, .. } =
worktree_changes.unified_diff(&repo, UI_CONTEXT_LINES)?
else {
bail!("No hunks available for given '{path}'")
Expand Down
4 changes: 4 additions & 0 deletions crates/but-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ pub enum UnifiedDiff {
size_in_bytes: u64,
},
/// A patch that if applied to the previous state of the resource would yield the current state.
#[serde(rename_all = "camelCase")]
Patch {
/// All non-overlapping hunks, including their context lines.
hunks: Vec<unified_diff::DiffHunk>,
/// If `true`, a binary to text filter (`textconv` in Git config) was used to obtain the `hunks` in the diff.
/// This means hunk-based operations must be disabled.
is_result_of_binary_to_text_conversion: bool,
},
}

Expand Down
3 changes: 2 additions & 1 deletion crates/but-core/src/unified_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl UnifiedDiff {
}
let input = prep.interned_input();
UnifiedDiff::Patch {
is_result_of_binary_to_text_conversion: prep.old_or_new_is_derived,
hunks: gix::diff::blob::diff(
algorithm,
&input,
Expand All @@ -185,7 +186,7 @@ impl UnifiedDiff {
use gix::diff::blob::platform::resource::Data;
fn size_for_data(data: Data<'_>) -> Option<u64> {
match data {
Data::Missing | Data::Buffer(_) => None,
Data::Missing | Data::Buffer { .. } => None,
Data::Binary { size } => Some(size),
}
}
Expand Down
30 changes: 20 additions & 10 deletions crates/but-core/tests/core/diff/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,15 @@ fn worktree_changes_unified_diffs_json_example() -> anyhow::Result<()> {
"newLines": 1,
"diff": "@@ -1,0 +1,1 @@\n+content\n"
}
]
],
"isResultOfBinaryToTextConversion": false
}
},
{
"type": "Patch",
"subject": {
"hunks": []
"hunks": [],
"isResultOfBinaryToTextConversion": false
}
},
{
Expand All @@ -610,7 +612,8 @@ fn worktree_changes_unified_diffs_json_example() -> anyhow::Result<()> {
"newLines": 1,
"diff": "@@ -1,0 +1,1 @@\n+link-target\n"
}
]
],
"isResultOfBinaryToTextConversion": false
}
},
{
Expand All @@ -624,7 +627,8 @@ fn worktree_changes_unified_diffs_json_example() -> anyhow::Result<()> {
"newLines": 1,
"diff": "@@ -1,0 +1,1 @@\n+content not to add to the index\n"
}
]
],
"isResultOfBinaryToTextConversion": false
}
},
{
Expand All @@ -638,7 +642,8 @@ fn worktree_changes_unified_diffs_json_example() -> anyhow::Result<()> {
"newLines": 1,
"diff": "@@ -1,0 +1,1 @@\n+change-in-index\n"
}
]
],
"isResultOfBinaryToTextConversion": false
}
},
{
Expand All @@ -652,13 +657,15 @@ fn worktree_changes_unified_diffs_json_example() -> anyhow::Result<()> {
"newLines": 1,
"diff": "@@ -1,0 +1,1 @@\n+change-in-worktree\n"
}
]
],
"isResultOfBinaryToTextConversion": false
}
},
{
"type": "Patch",
"subject": {
"hunks": []
"hunks": [],
"isResultOfBinaryToTextConversion": false
}
},
{
Expand All @@ -672,19 +679,22 @@ fn worktree_changes_unified_diffs_json_example() -> anyhow::Result<()> {
"newLines": 1,
"diff": "@@ -1,0 +1,1 @@\n+worktree-change\n"
}
]
],
"isResultOfBinaryToTextConversion": false
}
},
{
"type": "Patch",
"subject": {
"hunks": []
"hunks": [],
"isResultOfBinaryToTextConversion": false
}
},
{
"type": "Patch",
"subject": {
"hunks": []
"hunks": [],
"isResultOfBinaryToTextConversion": false
}
}
]
Expand Down
Loading
Loading