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
215 changes: 106 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/but-action/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use schemars::{JsonSchema, schema_for};

use crate::OpenAiProvider;

#[allow(dead_code)]
#[expect(dead_code)]
pub fn commit_message_blocking(
openai: &OpenAiProvider,
external_summary: &str,
Expand Down
4 changes: 2 additions & 2 deletions crates/but-action/src/grouping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum BranchSuggestion {
}

impl BranchSuggestion {
#[allow(dead_code)]
#[expect(dead_code)]
pub fn name(&self) -> String {
match self {
BranchSuggestion::New(name) => name.clone(),
Expand Down Expand Up @@ -63,7 +63,7 @@ pub struct Grouping {
pub groups: Vec<Group>,
}

#[allow(dead_code)]
#[expect(dead_code)]
pub fn group(openai: &OpenAiProvider, project_status: &ProjectStatus) -> anyhow::Result<Grouping> {
let system_message ="
You are an expert in grouping file changes into logical units for version control.
Expand Down
5 changes: 0 additions & 5 deletions crates/but-action/src/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use schemars::{JsonSchema, schema_for};
use serde::de::DeserializeOwned;
use tokio::sync::Mutex;

#[allow(unused)]
#[derive(Debug, Clone, serde::Serialize, strum::Display)]
pub enum CredentialsKind {
EnvVarOpenAiKey,
Expand Down Expand Up @@ -116,7 +115,6 @@ impl OpenAiProvider {
}
}

#[allow(dead_code)]
pub fn structured_output_blocking<
T: serde::Serialize + DeserializeOwned + JsonSchema + std::marker::Send + 'static,
>(
Expand Down Expand Up @@ -144,7 +142,6 @@ pub fn structured_output_blocking<
.unwrap()
}

#[allow(dead_code)]
pub async fn structured_output<T: serde::Serialize + DeserializeOwned + JsonSchema>(
client: &Client<OpenAIConfig>,
messages: Vec<ChatCompletionRequestMessage>,
Expand Down Expand Up @@ -177,7 +174,6 @@ pub async fn structured_output<T: serde::Serialize + DeserializeOwned + JsonSche
Ok(None)
}

#[allow(dead_code)]
pub fn tool_calling_blocking(
client: &OpenAiProvider,
messages: Vec<ChatCompletionRequestMessage>,
Expand All @@ -197,7 +193,6 @@ pub fn tool_calling_blocking(
.unwrap()
}

#[allow(dead_code)]
pub async fn tool_calling(
client: &Client<OpenAIConfig>,
messages: Vec<ChatCompletionRequestMessage>,
Expand Down
24 changes: 22 additions & 2 deletions crates/but-core/src/diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use bstr::{BStr, ByteSlice};
pub use tree_changes::tree_changes;

mod worktree;
use crate::{ChangeState, ModeFlags, TreeChange, TreeStatus, TreeStatusKind};
pub use worktree::worktree_changes;
use crate::{
ChangeState, IgnoredWorktreeChange, ModeFlags, TreeChange, TreeStatus, TreeStatusKind,
};
pub use worktree::{worktree_changes, worktree_changes_no_renames};

/// conversion functions for use in the UI
pub mod ui;
Expand Down Expand Up @@ -59,6 +61,24 @@ impl TreeChange {
}
}

impl std::fmt::Debug for TreeChange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TreeChange")
.field("path", &self.path)
.field("status", &self.status)
.finish()
}
}

impl std::fmt::Debug for IgnoredWorktreeChange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("IgnoredWorktreeChange")
.field("path", &self.path)
.field("status", &self.status)
.finish()
}
}

impl ModeFlags {
fn calculate(old: &ChangeState, new: &ChangeState) -> Option<Self> {
Self::calculate_inner(old.kind, new.kind)
Expand Down
4 changes: 4 additions & 0 deletions crates/but-core/src/diff/tree_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl From<gix::object::tree::diff::ChangeDetached> for TreeChange {
},
is_untracked: false,
},
status_item: None,
},
Change::Deletion {
location,
Expand All @@ -95,6 +96,7 @@ impl From<gix::object::tree::diff::ChangeDetached> for TreeChange {
kind: entry_mode.kind(),
},
},
status_item: None,
},
Change::Modification {
location,
Expand All @@ -118,6 +120,7 @@ impl From<gix::object::tree::diff::ChangeDetached> for TreeChange {
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: None,
}
}
Change::Rewrite {
Expand Down Expand Up @@ -147,6 +150,7 @@ impl From<gix::object::tree::diff::ChangeDetached> for TreeChange {
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: None,
}
}
}
Expand Down
71 changes: 59 additions & 12 deletions crates/but-core/src/diff/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,44 @@ enum Origin {
/// to get a commit with a tree equal to the current worktree.
#[instrument(skip(repo), err(Debug))]
pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChanges> {
let rewrites = gix::diff::Rewrites::default(); /* standard Git rewrite handling for everything */
debug_assert!(
rewrites.copies.is_none(),
"TODO: copy tracking needs specific support wherever 'previous_path()' is called."
);
worktree_changes_inner(repo, RenameTracking::Always)
}

/// Just like [`worktree_changes()`], but don't do any rename tracking for performance.
#[instrument(skip(repo), err(Debug))]
pub fn worktree_changes_no_renames(repo: &gix::Repository) -> anyhow::Result<WorktreeChanges> {
worktree_changes_inner(repo, RenameTracking::Disabled)
}

enum RenameTracking {
Always,
Disabled,
}

fn worktree_changes_inner(
repo: &gix::Repository,
renames: RenameTracking,
) -> anyhow::Result<WorktreeChanges> {
let (tree_index_rewrites, worktree_rewrites) = match renames {
RenameTracking::Always => {
let rewrites = gix::diff::Rewrites::default(); /* standard Git rewrite handling for everything */
debug_assert!(
rewrites.copies.is_none(),
"TODO: copy tracking needs specific support wherever 'previous_path()' is called."
);
(TrackRenames::Given(rewrites), Some(rewrites))
}
RenameTracking::Disabled => (TrackRenames::Disabled, None),
};
let has_submodule_ignore_configuration = repo.modules()?.is_some_and(|modules| {
modules
.names()
.any(|name| modules.ignore(name).ok().flatten().is_some())
});
let status_changes = repo
.status(gix::progress::Discard)?
.tree_index_track_renames(TrackRenames::Given(rewrites))
.index_worktree_rewrites(rewrites)
.tree_index_track_renames(tree_index_rewrites)
.index_worktree_rewrites(worktree_rewrites)
// Learn about submodule changes, but only do the cheap checks, showing only what we could commit.
.index_worktree_submodules(if has_submodule_ignore_configuration {
gix::status::Submodule::AsConfigured { check_dirty: true }
Expand Down Expand Up @@ -75,7 +99,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
let mut ignored_changes = Vec::new();
for change in status_changes {
let change = change?;
let change = match change {
let change = match change.clone() {
status::Item::TreeIndex(gix::diff::index::Change::Deletion {
location,
id,
Expand All @@ -91,6 +115,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
},
},
path: location.into_owned(),
status_item: Some(change),
},
),
status::Item::TreeIndex(gix::diff::index::Change::Addition {
Expand All @@ -109,6 +134,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
kind: into_tree_entry_kind(entry_mode)?,
},
},
status_item: Some(change),
},
),
status::Item::TreeIndex(gix::diff::index::Change::Modification {
Expand Down Expand Up @@ -136,6 +162,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand All @@ -154,6 +181,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
kind: into_tree_entry_kind(entry.mode)?,
},
},
status_item: Some(change),
},
),
status::Item::IndexWorktree(index_worktree::Item::Modification {
Expand All @@ -180,6 +208,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand Down Expand Up @@ -216,6 +245,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand All @@ -237,6 +267,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
},
is_untracked: false,
},
status_item: Some(change),
},
),
status::Item::IndexWorktree(index_worktree::Item::DirectoryContents {
Expand Down Expand Up @@ -269,17 +300,20 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
},
is_untracked: true,
},
status_item: Some(change),
},
)
}
status::Item::IndexWorktree(index_worktree::Item::Modification {
rela_path,
entry,
status:
EntryStatus::Change(index_as_worktree::Change::SubmoduleModification(change)),
EntryStatus::Change(index_as_worktree::Change::SubmoduleModification(
submodule_change,
)),
..
}) => {
let Some(checked_out_head_id) = change.checked_out_head_id else {
let Some(checked_out_head_id) = submodule_change.checked_out_head_id else {
continue;
};
// We can arrive here if the user configures to `ignore = none`, and there are
Expand All @@ -306,6 +340,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand Down Expand Up @@ -361,6 +396,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand Down Expand Up @@ -391,17 +427,19 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
status::Item::IndexWorktree(index_worktree::Item::Modification {
rela_path,
status: EntryStatus::Conflict(_conflict),
status: EntryStatus::Conflict { .. },
..
}) => {
ignored_changes.push(IgnoredWorktreeChange {
path: rela_path,
status: IgnoredWorktreeTreeChangeStatus::Conflict,
status_item: Some(change),
});
continue;
}
Expand Down Expand Up @@ -470,15 +508,17 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
changes.push(merged);
IgnoredWorktreeTreeChangeStatus::TreeIndex
}
[Some(first), Some(second)] => {
[Some(mut first), Some(mut second)] => {
ignored_changes.push(IgnoredWorktreeChange {
path: first.path.clone(),
status: IgnoredWorktreeTreeChangeStatus::TreeIndex,
status_item: first.status_item.take(),
});
changes.push(first);
ignored_changes.push(IgnoredWorktreeChange {
path: second.path.clone(),
status: IgnoredWorktreeTreeChangeStatus::TreeIndex,
status_item: second.status_item.take(),
});
changes.push(second);
continue;
Expand All @@ -487,6 +527,7 @@ pub fn worktree_changes(repo: &gix::Repository) -> anyhow::Result<WorktreeChange
ignored_changes.push(IgnoredWorktreeChange {
path: change_path,
status,
status_item: None,
});
continue;
}
Expand Down Expand Up @@ -655,6 +696,8 @@ fn merge_changes(
status: TreeStatus::Deletion {
previous_state: *previous_state,
},
// NOTE: not relevant, as renames are disabled for snapshots where this is used.
status_item: None,
}));
}
(
Expand All @@ -674,6 +717,8 @@ fn merge_changes(
// It's just in the index, which to us doesn't exist.
is_untracked: true,
},
// NOTE: not relevant, as renames are disabled for snapshots where this is used.
status_item: None,
}),
Some(TreeChange {
path: index_wt.path,
Expand All @@ -685,6 +730,8 @@ fn merge_changes(
// read the initial state of a file from.
is_untracked: true,
},
// NOTE: not relevant, as renames are disabled for snapshots where this is used.
status_item: None,
}),
]);
}
Expand Down
Loading
Loading