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
9 changes: 0 additions & 9 deletions crates/but-core/src/diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ 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")
Expand Down
4 changes: 0 additions & 4 deletions crates/but-core/src/diff/tree_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ impl From<gix::object::tree::diff::ChangeDetached> for TreeChange {
},
is_untracked: false,
},
status_item: None,
},
Change::Deletion {
location,
Expand All @@ -96,7 +95,6 @@ impl From<gix::object::tree::diff::ChangeDetached> for TreeChange {
kind: entry_mode.kind(),
},
},
status_item: None,
},
Change::Modification {
location,
Expand All @@ -120,7 +118,6 @@ 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 @@ -150,7 +147,6 @@ impl From<gix::object::tree::diff::ChangeDetached> for TreeChange {
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: None,
}
}
}
Expand Down
128 changes: 75 additions & 53 deletions crates/but-core/src/diff/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,74 +97,102 @@ fn worktree_changes_inner(
let work_dir = repo.workdir().context("need non-bare repository")?;
let mut tmp = Vec::new();
let mut ignored_changes = Vec::new();
let mut index_conflicts = Vec::new();
let mut index_changes = Vec::new();
for change in status_changes {
let change = change?;
let change = match change.clone() {
let change = match change {
status::Item::TreeIndex(gix::diff::index::Change::Deletion {
location,
index,
id,
entry_mode,
..
}) => (
Origin::TreeIndex,
TreeChange {
status: TreeStatus::Deletion {
previous_state: ChangeState {
id: id.into_owned(),
kind: into_tree_entry_kind(entry_mode)?,
}) => {
let res = (
Origin::TreeIndex,
TreeChange {
status: TreeStatus::Deletion {
previous_state: ChangeState {
id: id.clone().into_owned(),
kind: into_tree_entry_kind(entry_mode)?,
},
},
path: location.clone().into_owned(),
},
path: location.into_owned(),
status_item: Some(change),
},
),
);
index_changes.push(gix::diff::index::Change::Deletion {
location,
index,
id,
entry_mode,
});
res
}
status::Item::TreeIndex(gix::diff::index::Change::Addition {
location,
index,
entry_mode,
id,
..
}) => (
Origin::TreeIndex,
TreeChange {
path: location.into_owned(),
status: TreeStatus::Addition {
is_untracked: false,
state: ChangeState {
id: id.into_owned(),
kind: into_tree_entry_kind(entry_mode)?,
}) => {
let res = (
Origin::TreeIndex,
TreeChange {
path: location.clone().into_owned(),
status: TreeStatus::Addition {
is_untracked: false,
state: ChangeState {
id: id.clone().into_owned(),
kind: into_tree_entry_kind(entry_mode)?,
},
},
},
status_item: Some(change),
},
),
);
index_changes.push(gix::diff::index::ChangeRef::Addition {
location,
index,
entry_mode,
id,
});
res
}
status::Item::TreeIndex(gix::diff::index::Change::Modification {
location,
previous_index,
previous_entry_mode,
index,
entry_mode,
previous_id,
id,
..
}) => {
let previous_state = ChangeState {
id: previous_id.into_owned(),
id: previous_id.clone().into_owned(),
kind: into_tree_entry_kind(previous_entry_mode)?,
};
let state = ChangeState {
id: id.into_owned(),
id: id.clone().into_owned(),
kind: into_tree_entry_kind(entry_mode)?,
};
(
let res = (
Origin::TreeIndex,
TreeChange {
path: location.into_owned(),
path: location.clone().into_owned(),
status: TreeStatus::Modification {
previous_state,
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
);
index_changes.push(gix::diff::index::Change::Modification {
location,
previous_index,
previous_entry_mode,
previous_id,
index,
entry_mode,
id,
});
res
}
status::Item::IndexWorktree(index_worktree::Item::Modification {
rela_path,
Expand All @@ -181,7 +209,6 @@ fn worktree_changes_inner(
kind: into_tree_entry_kind(entry.mode)?,
},
},
status_item: Some(change),
},
),
status::Item::IndexWorktree(index_worktree::Item::Modification {
Expand All @@ -208,7 +235,6 @@ fn worktree_changes_inner(
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand Down Expand Up @@ -245,7 +271,6 @@ fn worktree_changes_inner(
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand All @@ -267,7 +292,6 @@ fn worktree_changes_inner(
},
is_untracked: false,
},
status_item: Some(change),
},
),
status::Item::IndexWorktree(index_worktree::Item::DirectoryContents {
Expand Down Expand Up @@ -300,7 +324,6 @@ fn worktree_changes_inner(
},
is_untracked: true,
},
status_item: Some(change),
},
)
}
Expand Down Expand Up @@ -340,7 +363,6 @@ fn worktree_changes_inner(
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand Down Expand Up @@ -396,7 +418,6 @@ fn worktree_changes_inner(
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
Expand Down Expand Up @@ -427,19 +448,18 @@ fn worktree_changes_inner(
state,
flags: ModeFlags::calculate(&previous_state, &state),
},
status_item: Some(change),
},
)
}
status::Item::IndexWorktree(index_worktree::Item::Modification {
rela_path,
status: EntryStatus::Conflict { .. },
status: EntryStatus::Conflict { entries, .. },
..
}) => {
index_conflicts.push((rela_path.clone(), entries));
ignored_changes.push(IgnoredWorktreeChange {
path: rela_path,
status: IgnoredWorktreeTreeChangeStatus::Conflict,
status_item: Some(change),
});
continue;
}
Expand Down Expand Up @@ -508,17 +528,15 @@ fn worktree_changes_inner(
changes.push(merged);
IgnoredWorktreeTreeChangeStatus::TreeIndex
}
[Some(mut first), Some(mut second)] => {
[Some(first), Some(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 @@ -527,7 +545,6 @@ fn worktree_changes_inner(
ignored_changes.push(IgnoredWorktreeChange {
path: change_path,
status,
status_item: None,
});
continue;
}
Expand All @@ -538,6 +555,8 @@ fn worktree_changes_inner(
Ok(WorktreeChanges {
changes,
ignored_changes,
index_changes,
index_conflicts,
})
}

Expand Down Expand Up @@ -696,8 +715,6 @@ 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 @@ -717,8 +734,6 @@ 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 @@ -730,8 +745,6 @@ 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 Expand Up @@ -935,3 +948,12 @@ impl TreeChange {
}
}
}

impl std::fmt::Debug for WorktreeChanges {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("WorktreeChanges")
.field("changes", &self.changes)
.field("ignored_changes", &self.ignored_changes)
.finish()
}
}
17 changes: 7 additions & 10 deletions crates/but-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use bstr::BString;
use gix::object::tree::EntryKind;
use gix::refs::FullNameRef;
use gix::status::plumbing::index_as_worktree::ConflictIndexEntry;
use serde::Serialize;
use std::any::Any;
use std::ops::{Deref, DerefMut};
Expand Down Expand Up @@ -233,16 +234,12 @@ pub fn open_repo(path: impl Into<PathBuf>) -> anyhow::Result<gix::Repository> {
///
/// For simplicity, copy-tracking is not representable right now, but `copy: bool` could be added
/// if needed. Copy-tracking is deactivated as well.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct TreeChange {
/// The *relative* path in the worktree where the entry can be found.
pub path: BString,
/// The specific information about this change.
pub status: TreeStatus,
/// The status item that this change is derived from, used in places that need detailed information.
/// This is only set if this instance was created from a worktree-status, and is `None` when created
/// from a tree-diff.
pub status_item: Option<gix::status::Item>,
}

/// Specifically defines a [`TreeChange`].
Expand Down Expand Up @@ -339,19 +336,19 @@ pub struct IgnoredWorktreeChange {
pub path: BString,
/// The status that caused this change to be ignored.
pub status: IgnoredWorktreeTreeChangeStatus,
/// The status item that this change is derived from, used in places that need detailed information.
/// It's `None` if the status item is already present in non-ignored changes.
#[serde(skip)]
pub status_item: Option<gix::status::Item>,
}

/// The type returned by [`worktree_changes()`](diff::worktree_changes).
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct WorktreeChanges {
/// Changes that could be committed.
pub changes: Vec<TreeChange>,
/// Changes that were in the index that we can't handle. The user can see them and interact with them to clear them out before a commit can be made.
pub ignored_changes: Vec<IgnoredWorktreeChange>,
/// All unprocessed changes to the index.
pub index_changes: Vec<gix::diff::index::Change>,
/// The conflicting index entries, along with their relative path `(rela_path, [Entries(base, ours, theirs)])`.
pub index_conflicts: Vec<(BString, Box<[Option<ConflictIndexEntry>; 3]>)>,
}

/// Computed using the file kinds/modes of two [`ChangeState`] instances to represent
Expand Down
Loading
Loading