Merge pull request #3760 from gitbutlerapp/update-snapshot-commit-creation-impl

update-snapshot-commit-creation-impl
This commit is contained in:
Kiril Videlov 2024-05-13 16:49:01 +02:00 committed by GitHub
commit 158ed5c15d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 6 deletions

View File

@ -133,6 +133,9 @@
</div>
{: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}
</div>
<div>

View File

@ -15,16 +15,39 @@ 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<String>,
) -> anyhow::Result<()>;
fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()>;
}
impl<T: Oplog> Snapshot for T {
fn snapshot_commit_creation(&self, commit_message: String) -> anyhow::Result<()> {
fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()> {
let details =
SnapshotDetails::new(OperationType::CreateCommit).with_trailers(vec![Trailer {
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,
sha: Option<String>,
) -> 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(())
}

View File

@ -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
})
}
@ -812,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
})
}