
@ 58e8eadb:43ac7c0e
2025-04-24 17:50:35
{"id":"98b8d1879728115a9e6b2730b6c31de3a3292a4d","tree":"9213d45a2b1102b895f1a77997c85cd408d1e9a4","parents":["d9faa02b0ec3c7b389eb5f269dadc4b6146e376b"],"author_name":"randymcmillan","author_email":"randymcmillan@protonmail.com","committer_name":"randymcmillan","committer_email":"randymcmillan@protonmail.com","message":"asyncgit/src/sync/commit.rs\n\ndiff --git a/asyncgit/src/sync/commit.rs b/asyncgit/src/sync/commit.rs\nindex 1b2e074c..beb3caef 100644\n--- a/asyncgit/src/sync/commit.rs\n+++ b/asyncgit/src/sync/commit.rs\n@@ -1,7 +1,14 @@\n //! Git Api for Commits\n+//use anyhow::anyhow;\n use git2::{\n-\tErrorCode, ObjectType, Repository, Signature, message_prettify,\n+\tCommit, ErrorCode, ObjectType, Oid, Repository, Signature, message_prettify,\n };\n+\n+use serde::{Deserialize, Serialize};\n+use serde_json;\n+//?use nostr_sdk::serde_json;\n+//use serde_json::{Result as SerdeJsonResult, Value};\n+use log::debug;\n use scopetime::scope_time;\n\n use super::{CommitId, RepoPath};\n@@ -83,6 +90,69 @@ pub(crate) fn signature_allow_undefined_name(\n \tsignature\n }\n\n+#[derive(Serialize, Deserialize, Debug)]\n+struct SerializableCommit {\n+ id: String,\n+ tree: String,\n+ parents: Vec,\n+ author_name: String,\n+ author_email: String,\n+ committer_name: String,\n+ committer_email: String,\n+ message: String,\n+ time: i64,\n+}\n+///\n+pub fn serialize_commit(commit: &Commit) -> Result {\n+ let id = commit.id().to_string();\n+ let tree = commit.tree_id().to_string();\n+ let parents = commit.parent_ids().map(|oid| oid.to_string()).collect();\n+ let author = commit.author();\n+ let committer = commit.committer();\n+ let message = commit\n+ .message()\n+ .ok_or(log::debug!(\"No commit message\")).expect(\"\")\n+ .to_string();\n+ log::debug!(\"message:\\n{:?}\", message);\n+ let time = commit.time().seconds();\n+ debug!(\"time: {:?}\", time);\n+\n+ let serializable_commit = SerializableCommit {\n+ id,\n+ tree,\n+ parents,\n+ author_name: author.name().unwrap_or_default().to_string(),\n+ author_email: author.email().unwrap_or_default().to_string(),\n+ committer_name: committer.name().unwrap_or_default().to_string(),\n+ committer_email: committer.email().unwrap_or_default().to_string(),\n+ message,\n+ time,\n+ };\n+\n+ let serialized = serde_json::to_string(&serializable_commit).expect(\"\");\n+ debug!(\"serialized_commit: {:?}\", serialized);\n+ Ok(serialized)\n+}\n+///\n+pub fn deserialize_commit<'a>(repo: &'a Repository, data: &'a str) -> Result> {\n+ //we serialize the commit data\n+ //easier to grab the commit.id\n+ let serializable_commit: SerializableCommit = serde_json::from_str(data).expect(\"\");\n+ //grab the commit.id\n+ let oid = Oid::from_str(&serializable_commit.id)?;\n+ //oid used to search the repo\n+ let commit_obj = repo.find_object(oid, Some(ObjectType::Commit))?;\n+ //grab the commit\n+ let commit = commit_obj.peel_to_commit()?;\n+ //confirm we grabbed the correct commit\n+ //if commit.id().to_string() != serializable_commit.id {\n+ // return Err(eprintln!(\"Commit ID mismatch during deserialization\"));\n+ //}\n+ //return the commit\n+ Ok(commit)\n+}\n+\n+\n /// this does not run any git hooks, git-hooks have to be executed\n /// manually, checkout `hooks_commit_msg` for example\n pub fn commit(repo_path: &RepoPath, msg: &str) -> Result {\n","time":1745516726}