Update terminology

This commit is contained in:
Caleb Owens 2024-08-19 13:25:46 +02:00
parent 59f65983ac
commit 17d15719ce
7 changed files with 65 additions and 66 deletions

View File

@ -34,7 +34,7 @@
</div>
<p class="switchrepo__title text-18 text-body text-bold">
You are currently editing commit <span class="code-string">
{editModeMetadata.editeeCommitSha.slice(0, 7)}
{editModeMetadata.commitOid.slice(0, 7)}
</span>
</p>

View File

@ -2,8 +2,8 @@ import { invoke, listen } from '$lib/backend/ipc';
import { derived, writable } from 'svelte/store';
export interface EditModeMetadata {
editeeCommitSha: string;
editeeBranch: string;
commitOid: string;
branchReference: string;
}
type Mode =
@ -41,11 +41,11 @@ export class ModeService {
this.headAndMode.set({ head, operatingMode });
}
async enterEditMode(editeeCommitId: string, editeeBranchRef: string) {
async enterEditMode(commitOid: string, branchReference: string) {
await invoke('enter_edit_mode', {
projectId: this.projectId,
editee: editeeCommitId,
editeeBranch: editeeBranchRef
commitOid,
branchReference
});
}

View File

@ -10,30 +10,30 @@ use gitbutler_reference::ReferenceName;
pub fn enter_edit_mode(
project: &Project,
editee: git2::Oid,
editee_branch: ReferenceName,
commit_oid: git2::Oid,
branch_reference_name: ReferenceName,
) -> Result<EditModeMetadata> {
let (ctx, mut guard) = open_with_permission(project)?;
assure_open_workspace_mode(&ctx)
.context("Entering edit mode may only be done when the workspace is open")?;
let editee = ctx
let commit = ctx
.repository()
.find_commit(editee)
.context("Failed to find editee commit")?;
.find_commit(commit_oid)
.context("Failed to find commit")?;
let editee_branch = ctx
let branch = ctx
.repository()
.find_reference(&editee_branch)
.context("Failed to find editee branch reference")?;
.find_reference(&branch_reference_name)
.context("Failed to find branch reference")?;
let snapshot = project
.prepare_snapshot(guard.read_permission())
.context("Failed to prepare snapshot")?;
let edit_mode_metadata =
crate::enter_edit_mode(&ctx, &editee, &editee_branch, guard.write_permission())?;
crate::enter_edit_mode(&ctx, &commit, &branch, guard.write_permission())?;
let _ = project.commit_snapshot(
snapshot,

View File

@ -63,13 +63,13 @@ fn save_uncommited_files(ctx: &CommandContext) -> Result<()> {
Ok(())
}
fn checkout_edit_branch(ctx: &CommandContext, editee: &git2::Commit) -> Result<()> {
fn checkout_edit_branch(ctx: &CommandContext, commit: &git2::Commit) -> Result<()> {
let repository = ctx.repository();
// Checkout editee's parent
let editee_parent = editee.parent(0).context("Failed to get editee's parent")?;
// Checkout commits's parent
let commit_parent = commit.parent(0).context("Failed to get commit's parent")?;
repository
.reference(EDIT_BRANCH_REF, editee_parent.id(), true, "")
.reference(EDIT_BRANCH_REF, commit_parent.id(), true, "")
.context("Failed to update edit branch reference")?;
repository
.set_head(EDIT_BRANCH_REF)
@ -78,14 +78,14 @@ fn checkout_edit_branch(ctx: &CommandContext, editee: &git2::Commit) -> Result<(
.checkout_head(Some(CheckoutBuilder::new().force().remove_untracked(true)))
.context("Failed to checkout head")?;
// Checkout the editee as unstaged changes
let editee_tree = editee.tree().context("Failed to get editee's tree")?;
// Checkout the commit as unstaged changes
let commit_tree = commit.tree().context("Failed to get commit's tree")?;
repository
.checkout_tree(
editee_tree.as_object(),
commit_tree.as_object(),
Some(CheckoutBuilder::new().force().remove_untracked(true)),
)
.context("Failed to checkout editee")?;
.context("Failed to checkout commit")?;
Ok(())
}
@ -104,35 +104,35 @@ fn find_virtual_branch_by_reference(
return false;
};
let Ok(editee_refname) = Refname::from_str(reference) else {
let Ok(checked_out_refname) = Refname::from_str(reference) else {
return false;
};
editee_refname == refname.into()
checked_out_refname == refname.into()
}))
}
pub(crate) fn enter_edit_mode(
ctx: &CommandContext,
editee: &git2::Commit,
editee_branch: &git2::Reference,
commit: &git2::Commit,
branch: &git2::Reference,
_perm: &mut WorktreeWritePermission,
) -> Result<EditModeMetadata> {
let Some(editee_branch) = editee_branch.name() else {
bail!("Failed to get editee branch name");
let Some(branch_reference) = branch.name() else {
bail!("Failed to get branch reference name");
};
let edit_mode_metadata = EditModeMetadata {
editee_commit_sha: editee.id(),
editee_branch: editee_branch.to_string().into(),
commit_oid: commit.id(),
branch_reference: branch_reference.to_string().into(),
};
if find_virtual_branch_by_reference(ctx, &edit_mode_metadata.editee_branch)?.is_none() {
if find_virtual_branch_by_reference(ctx, &edit_mode_metadata.branch_reference)?.is_none() {
bail!("Can not enter edit mode for a reference which does not have a cooresponding virtual branch")
}
save_uncommited_files(ctx).context("Failed to save uncommited files")?;
checkout_edit_branch(ctx, editee).context("Failed to checkout edit branch")?;
checkout_edit_branch(ctx, commit).context("Failed to checkout edit branch")?;
write_edit_mode_metadata(ctx, &edit_mode_metadata).context("Failed to persist metadata")?;
Ok(edit_mode_metadata)
@ -147,10 +147,10 @@ pub(crate) fn save_and_return_to_workspace(
let vb_state = VirtualBranchesHandle::new(ctx.project().gb_dir());
// Get important references
let editee = repository
.find_commit(edit_mode_metadata.editee_commit_sha)
.context("Failed to find editee")?;
let editee_parent = editee.parent(0).context("Failed to get editee's parent")?;
let commit = repository
.find_commit(edit_mode_metadata.commit_oid)
.context("Failed to find commit")?;
let commit_parent = commit.parent(0).context("Failed to get commit's parent")?;
let stashed_integration_changes_reference = repository
.find_reference(EDIT_UNCOMMITED_FILES_REF)
.context("Failed to find stashed integration changes")?;
@ -158,13 +158,13 @@ pub(crate) fn save_and_return_to_workspace(
.peel_to_commit()
.context("Failed to get stashed changes commit")?;
let Some(mut editee_virtual_branch) =
find_virtual_branch_by_reference(ctx, &edit_mode_metadata.editee_branch)?
let Some(mut virtual_branch) =
find_virtual_branch_by_reference(ctx, &edit_mode_metadata.branch_reference)?
else {
bail!("Failed to find virtual branch for this reference. Entering and leaving edit mode for non-virtual branches is unsupported")
};
// Recommit editee
// Recommit commit
let mut index = repository.index().context("Failed to get index")?;
index
.add_all(["*"].iter(), git2::IndexAddOption::DEFAULT, None)
@ -176,32 +176,31 @@ pub(crate) fn save_and_return_to_workspace(
let tree = repository
.find_tree(tree_oid)
.context("Failed to find tree")?;
let new_editee_oid = ctx
let new_commit_oid = ctx
.repository()
.commit_with_signature(
None,
&editee.author(),
&editee.committer(),
&editee.message_bstr().to_str_lossy(),
&commit.author(),
&commit.committer(),
&commit.message_bstr().to_str_lossy(),
&tree,
&[&editee_parent],
editee.gitbutler_headers(),
&[&commit_parent],
commit.gitbutler_headers(),
)
.context("Failed to commit new editee")?;
.context("Failed to commit new commit")?;
// Rebase all all commits on top of the new editee and update reference
let new_editee_branch_head =
cherry_rebase(ctx, new_editee_oid, editee.id(), editee_virtual_branch.head)
.context("Failed to rebase commits onto new editee")?
.unwrap_or(new_editee_oid);
// Rebase all all commits on top of the new commit and update reference
let new_branch_head = cherry_rebase(ctx, new_commit_oid, commit.id(), virtual_branch.head)
.context("Failed to rebase commits onto new commit")?
.unwrap_or(new_commit_oid);
repository
.reference(
&edit_mode_metadata.editee_branch,
new_editee_branch_head,
&edit_mode_metadata.branch_reference,
new_branch_head,
true,
"",
)
.context("Failed to reference new editee branch head")?;
.context("Failed to reference new commit branch head")?;
// Move back to gitbutler/integration and restore stashed changes
{
@ -212,10 +211,10 @@ pub(crate) fn save_and_return_to_workspace(
.checkout_head(Some(CheckoutBuilder::new().force().remove_untracked(true)))
.context("Failed to checkout gitbutler/integration")?;
editee_virtual_branch.head = new_editee_branch_head;
editee_virtual_branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
virtual_branch.head = new_branch_head;
virtual_branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state
.set_branch(editee_virtual_branch)
.set_branch(virtual_branch)
.context("Failed to update vbstate")?;
let integration_commit_oid = update_gitbutler_integration(&vb_state, ctx)

View File

@ -46,9 +46,9 @@ pub fn write_edit_mode_metadata(
pub struct EditModeMetadata {
/// The sha of the commit getting edited.
#[serde(with = "gitbutler_serde::oid")]
pub editee_commit_sha: git2::Oid,
pub commit_oid: git2::Oid,
/// The ref of the vbranch which owns this commit.
pub editee_branch: ReferenceName,
pub branch_reference: ReferenceName,
}
#[derive(PartialEq, Debug, Clone, Serialize)]

View File

@ -21,8 +21,8 @@ fn create_edit_mode_metadata(ctx: &CommandContext) {
write_edit_mode_metadata(
ctx,
&EditModeMetadata {
editee_branch: "asdf".into(),
editee_commit_sha: git2::Oid::zero(),
branch_reference: "asdf".into(),
commit_oid: git2::Oid::zero(),
},
)
.unwrap();

View File

@ -23,14 +23,14 @@ pub fn operating_mode(
pub fn enter_edit_mode(
projects: State<'_, Controller>,
project_id: ProjectId,
editee: String,
editee_branch: String,
commit_oid: String,
branch_reference: String,
) -> Result<EditModeMetadata, Error> {
let project = projects.get(project_id)?;
let editee = git2::Oid::from_str(&editee).context("Failed to parse editee oid")?;
let commit = git2::Oid::from_str(&commit_oid).context("Failed to parse commit oid")?;
gitbutler_edit_mode::commands::enter_edit_mode(&project, editee, editee_branch.into())
gitbutler_edit_mode::commands::enter_edit_mode(&project, commit, branch_reference.into())
.map_err(Into::into)
}