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

View File

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

View File

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

View File

@ -63,13 +63,13 @@ fn save_uncommited_files(ctx: &CommandContext) -> Result<()> {
Ok(()) 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(); let repository = ctx.repository();
// Checkout editee's parent // Checkout commits's parent
let editee_parent = editee.parent(0).context("Failed to get editee's parent")?; let commit_parent = commit.parent(0).context("Failed to get commit's parent")?;
repository repository
.reference(EDIT_BRANCH_REF, editee_parent.id(), true, "") .reference(EDIT_BRANCH_REF, commit_parent.id(), true, "")
.context("Failed to update edit branch reference")?; .context("Failed to update edit branch reference")?;
repository repository
.set_head(EDIT_BRANCH_REF) .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))) .checkout_head(Some(CheckoutBuilder::new().force().remove_untracked(true)))
.context("Failed to checkout head")?; .context("Failed to checkout head")?;
// Checkout the editee as unstaged changes // Checkout the commit as unstaged changes
let editee_tree = editee.tree().context("Failed to get editee's tree")?; let commit_tree = commit.tree().context("Failed to get commit's tree")?;
repository repository
.checkout_tree( .checkout_tree(
editee_tree.as_object(), commit_tree.as_object(),
Some(CheckoutBuilder::new().force().remove_untracked(true)), Some(CheckoutBuilder::new().force().remove_untracked(true)),
) )
.context("Failed to checkout editee")?; .context("Failed to checkout commit")?;
Ok(()) Ok(())
} }
@ -104,35 +104,35 @@ fn find_virtual_branch_by_reference(
return false; return false;
}; };
let Ok(editee_refname) = Refname::from_str(reference) else { let Ok(checked_out_refname) = Refname::from_str(reference) else {
return false; return false;
}; };
editee_refname == refname.into() checked_out_refname == refname.into()
})) }))
} }
pub(crate) fn enter_edit_mode( pub(crate) fn enter_edit_mode(
ctx: &CommandContext, ctx: &CommandContext,
editee: &git2::Commit, commit: &git2::Commit,
editee_branch: &git2::Reference, branch: &git2::Reference,
_perm: &mut WorktreeWritePermission, _perm: &mut WorktreeWritePermission,
) -> Result<EditModeMetadata> { ) -> Result<EditModeMetadata> {
let Some(editee_branch) = editee_branch.name() else { let Some(branch_reference) = branch.name() else {
bail!("Failed to get editee branch name"); bail!("Failed to get branch reference name");
}; };
let edit_mode_metadata = EditModeMetadata { let edit_mode_metadata = EditModeMetadata {
editee_commit_sha: editee.id(), commit_oid: commit.id(),
editee_branch: editee_branch.to_string().into(), 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") 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")?; 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")?; write_edit_mode_metadata(ctx, &edit_mode_metadata).context("Failed to persist metadata")?;
Ok(edit_mode_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()); let vb_state = VirtualBranchesHandle::new(ctx.project().gb_dir());
// Get important references // Get important references
let editee = repository let commit = repository
.find_commit(edit_mode_metadata.editee_commit_sha) .find_commit(edit_mode_metadata.commit_oid)
.context("Failed to find editee")?; .context("Failed to find commit")?;
let editee_parent = editee.parent(0).context("Failed to get editee's parent")?; let commit_parent = commit.parent(0).context("Failed to get commit's parent")?;
let stashed_integration_changes_reference = repository let stashed_integration_changes_reference = repository
.find_reference(EDIT_UNCOMMITED_FILES_REF) .find_reference(EDIT_UNCOMMITED_FILES_REF)
.context("Failed to find stashed integration changes")?; .context("Failed to find stashed integration changes")?;
@ -158,13 +158,13 @@ pub(crate) fn save_and_return_to_workspace(
.peel_to_commit() .peel_to_commit()
.context("Failed to get stashed changes commit")?; .context("Failed to get stashed changes commit")?;
let Some(mut editee_virtual_branch) = let Some(mut virtual_branch) =
find_virtual_branch_by_reference(ctx, &edit_mode_metadata.editee_branch)? find_virtual_branch_by_reference(ctx, &edit_mode_metadata.branch_reference)?
else { else {
bail!("Failed to find virtual branch for this reference. Entering and leaving edit mode for non-virtual branches is unsupported") 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")?; let mut index = repository.index().context("Failed to get index")?;
index index
.add_all(["*"].iter(), git2::IndexAddOption::DEFAULT, None) .add_all(["*"].iter(), git2::IndexAddOption::DEFAULT, None)
@ -176,32 +176,31 @@ pub(crate) fn save_and_return_to_workspace(
let tree = repository let tree = repository
.find_tree(tree_oid) .find_tree(tree_oid)
.context("Failed to find tree")?; .context("Failed to find tree")?;
let new_editee_oid = ctx let new_commit_oid = ctx
.repository() .repository()
.commit_with_signature( .commit_with_signature(
None, None,
&editee.author(), &commit.author(),
&editee.committer(), &commit.committer(),
&editee.message_bstr().to_str_lossy(), &commit.message_bstr().to_str_lossy(),
&tree, &tree,
&[&editee_parent], &[&commit_parent],
editee.gitbutler_headers(), 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 // Rebase all all commits on top of the new commit and update reference
let new_editee_branch_head = let new_branch_head = cherry_rebase(ctx, new_commit_oid, commit.id(), virtual_branch.head)
cherry_rebase(ctx, new_editee_oid, editee.id(), editee_virtual_branch.head) .context("Failed to rebase commits onto new commit")?
.context("Failed to rebase commits onto new editee")? .unwrap_or(new_commit_oid);
.unwrap_or(new_editee_oid);
repository repository
.reference( .reference(
&edit_mode_metadata.editee_branch, &edit_mode_metadata.branch_reference,
new_editee_branch_head, new_branch_head,
true, 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 // 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))) .checkout_head(Some(CheckoutBuilder::new().force().remove_untracked(true)))
.context("Failed to checkout gitbutler/integration")?; .context("Failed to checkout gitbutler/integration")?;
editee_virtual_branch.head = new_editee_branch_head; virtual_branch.head = new_branch_head;
editee_virtual_branch.updated_timestamp_ms = gitbutler_time::time::now_ms(); virtual_branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state vb_state
.set_branch(editee_virtual_branch) .set_branch(virtual_branch)
.context("Failed to update vbstate")?; .context("Failed to update vbstate")?;
let integration_commit_oid = update_gitbutler_integration(&vb_state, ctx) 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 { pub struct EditModeMetadata {
/// The sha of the commit getting edited. /// The sha of the commit getting edited.
#[serde(with = "gitbutler_serde::oid")] #[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. /// The ref of the vbranch which owns this commit.
pub editee_branch: ReferenceName, pub branch_reference: ReferenceName,
} }
#[derive(PartialEq, Debug, Clone, Serialize)] #[derive(PartialEq, Debug, Clone, Serialize)]

View File

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

View File

@ -23,14 +23,14 @@ pub fn operating_mode(
pub fn enter_edit_mode( pub fn enter_edit_mode(
projects: State<'_, Controller>, projects: State<'_, Controller>,
project_id: ProjectId, project_id: ProjectId,
editee: String, commit_oid: String,
editee_branch: String, branch_reference: String,
) -> Result<EditModeMetadata, Error> { ) -> Result<EditModeMetadata, Error> {
let project = projects.get(project_id)?; 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) .map_err(Into::into)
} }