From 8849c9845eef20856bdb9c618a54bf3f5e2e016c Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Mon, 13 May 2024 16:24:40 +0200 Subject: [PATCH 1/2] add sha to commit snapshot --- app/src/lib/components/History.svelte | 1 + crates/gitbutler-core/src/ops/snapshot.rs | 23 +++++++++++++++---- .../src/virtual_branches/controller.rs | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/src/lib/components/History.svelte b/app/src/lib/components/History.svelte index a82c126bd..5068e4c38 100644 --- a/app/src/lib/components/History.svelte +++ b/app/src/lib/components/History.svelte @@ -133,6 +133,7 @@ {:else if ['CreateCommit'].includes(entry.details?.operation || '')} message: {entry.details?.trailers.find((t) => t.key === 'message')?.value} + sha: {entry.details?.trailers.find((t) => t.key === 'sha')?.value?.slice(0, 7)} {/if}
diff --git a/crates/gitbutler-core/src/ops/snapshot.rs b/crates/gitbutler-core/src/ops/snapshot.rs index 7ff87d0cc..e7f5de23c 100644 --- a/crates/gitbutler-core/src/ops/snapshot.rs +++ b/crates/gitbutler-core/src/ops/snapshot.rs @@ -15,16 +15,29 @@ pub trait Snapshot { old_branch: Branch, update: BranchUpdateRequest, ) -> anyhow::Result<()>; - fn snapshot_commit_creation(&self, commit_message: String) -> anyhow::Result<()>; + fn snapshot_commit_creation( + &self, + commit_message: String, + sha: Option, + ) -> anyhow::Result<()>; } impl Snapshot for T { - fn snapshot_commit_creation(&self, commit_message: String) -> anyhow::Result<()> { - let details = - SnapshotDetails::new(OperationType::CreateCommit).with_trailers(vec![Trailer { + fn snapshot_commit_creation( + &self, + commit_message: String, + sha: Option, + ) -> anyhow::Result<()> { + let details = SnapshotDetails::new(OperationType::CreateCommit).with_trailers(vec![ + Trailer { key: "message".to_string(), value: commit_message, - }]); + }, + Trailer { + key: "sha".to_string(), + value: sha.unwrap_or_default(), + }, + ]); self.create_snapshot(details)?; Ok(()) } diff --git a/crates/gitbutler-core/src/virtual_branches/controller.rs b/crates/gitbutler-core/src/virtual_branches/controller.rs index c74f11449..821964df5 100644 --- a/crates/gitbutler-core/src/virtual_branches/controller.rs +++ b/crates/gitbutler-core/src/virtual_branches/controller.rs @@ -483,9 +483,10 @@ impl ControllerInner { ) .map_err(Into::into); + let sha = result.as_ref().ok().map(|oid| oid.to_string()); let _ = project_repository .project() - .snapshot_commit_creation(message.to_owned()); + .snapshot_commit_creation(message.to_owned(), sha); result }) } From 80148f50fef5d09dfc0faf7a218fbdda1189a360 Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Mon, 13 May 2024 16:37:37 +0200 Subject: [PATCH 2/2] add sha to undo commit snapshot --- app/src/lib/components/History.svelte | 2 ++ crates/gitbutler-core/src/ops/snapshot.rs | 10 ++++++++++ .../gitbutler-core/src/virtual_branches/controller.rs | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/lib/components/History.svelte b/app/src/lib/components/History.svelte index 5068e4c38..14f8d9a06 100644 --- a/app/src/lib/components/History.svelte +++ b/app/src/lib/components/History.svelte @@ -134,6 +134,8 @@ {:else if ['CreateCommit'].includes(entry.details?.operation || '')} message: {entry.details?.trailers.find((t) => t.key === 'message')?.value} sha: {entry.details?.trailers.find((t) => t.key === 'sha')?.value?.slice(0, 7)} + {:else if ['UndoCommit', 'CreateCommit'].includes(entry.details?.operation || '')} + sha: {entry.details?.trailers.find((t) => t.key === 'sha')?.value?.slice(0, 7)} {/if}
diff --git a/crates/gitbutler-core/src/ops/snapshot.rs b/crates/gitbutler-core/src/ops/snapshot.rs index e7f5de23c..fa45074ff 100644 --- a/crates/gitbutler-core/src/ops/snapshot.rs +++ b/crates/gitbutler-core/src/ops/snapshot.rs @@ -20,9 +20,19 @@ pub trait Snapshot { commit_message: String, sha: Option, ) -> anyhow::Result<()>; + fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()>; } impl Snapshot for T { + fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()> { + let details = + SnapshotDetails::new(OperationType::UndoCommit).with_trailers(vec![Trailer { + key: "sha".to_string(), + value: commit_sha, + }]); + self.create_snapshot(details)?; + Ok(()) + } fn snapshot_commit_creation( &self, commit_message: String, diff --git a/crates/gitbutler-core/src/virtual_branches/controller.rs b/crates/gitbutler-core/src/virtual_branches/controller.rs index 821964df5..889942ba2 100644 --- a/crates/gitbutler-core/src/virtual_branches/controller.rs +++ b/crates/gitbutler-core/src/virtual_branches/controller.rs @@ -813,7 +813,7 @@ impl ControllerInner { super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into); let _ = project_repository .project() - .create_snapshot(SnapshotDetails::new(OperationType::UndoCommit)); + .snapshot_commit_undo(commit_oid.to_string()); result }) }