Skip to content

Commit 8a96e07

Browse files
Samod integration (#95)
Replaces automerge-repo-rs with samod. --------- Co-authored-by: nikitalita <[email protected]>
1 parent d24c999 commit 8a96e07

File tree

14 files changed

+441
-283
lines changed

14 files changed

+441
-283
lines changed

Cargo.lock

Lines changed: 182 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editor/patchwork_editor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,26 @@ void PatchworkEditor::refresh_after_source_change() {
546546
Main::iteration();
547547
}
548548

549+
auto current_scene = EditorInterface::get_singleton()->get_edited_scene_root();
550+
549551
auto open_scenes = EditorInterface::get_singleton()->get_open_scenes();
550552
for (auto &scene : open_scenes) {
553+
if (current_scene != nullptr && scene == current_scene->get_scene_file_path()) {
554+
continue;
555+
}
551556
while (is_changing_scene()) {
552557
OS::get_singleton()->delay_usec(10000);
553558
Main::iteration();
554559
}
555560
EditorInterface::get_singleton()->reload_scene_from_path(scene);
556561
}
562+
if (current_scene != nullptr) {
563+
while (is_changing_scene()) {
564+
OS::get_singleton()->delay_usec(10000);
565+
Main::iteration();
566+
}
567+
EditorInterface::get_singleton()->reload_scene_from_path(current_scene->get_scene_file_path());
568+
}
557569
}
558570

559571
Callable PatchworkEditor::steal_close_current_script_tab_file_callback() {

rust/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ automerge_0_6 = []
2121

2222
[dependencies]
2323
automerge = "0.7.2"
24-
automerge_repo = { version = "0.3.0", features = [
25-
"tokio",
26-
] }
2724
autosurgeon = "0.10.1"
2825
futures = "0.3.31"
2926
godot = "0.4.3"
@@ -56,6 +53,8 @@ rlimit = "0.10.2"
5653
tracing = "0.1.40"
5754
tracing-appender = "0.2.2"
5855
chrono = "0.4.31"
56+
samod = { git="https://github.com/LilithSilver/samod.git", branch="patchwork", features = ["tokio", "threadpool"] }
57+
rayon = "1.11.0"
5958

6059
[build-dependencies]
6160
cbindgen = "^0.27"

rust/src/fs/file_utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::{PathBuf};
55
use std::str;
66
use automerge::{Automerge, ChangeHash, ObjType, ReadDoc};
77
use automerge::ObjId;
8-
use automerge_repo::{DocumentId};
8+
use samod::{DocumentId};
99
use ya_md5::{Md5Hasher};
1010
use crate::helpers::doc_utils::SimpleDocReader;
1111
use crate::helpers::utils::{ToShortForm, parse_automerge_url};
@@ -81,7 +81,10 @@ impl FileContent {
8181
let scene = parse_scene(&string);
8282
if scene.is_ok() {
8383
return FileContent::Scene(scene.unwrap());
84+
} else if let Err(e) = scene {
85+
tracing::error!("Error parsing scene: {:?}", e);
8486
}
87+
8588
}
8689
FileContent::String(string)
8790
}

rust/src/helpers/branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use automerge::ChangeHash;
2-
use automerge_repo::{DocHandle, DocumentId};
2+
use samod::{DocHandle, DocumentId};
33
use autosurgeon::{Hydrate, Reconcile};
44
use std::collections::{HashMap, HashSet};
55

rust/src/helpers/tracing.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ pub fn initialize_tracing() {
3737
.with_writer(CustomStdoutWriter::custom_stdout)
3838
.with_filter(EnvFilter::new("info")
3939
.add_directive("patchwork_rust_core=debug".parse().unwrap())
40-
.add_directive("automerge_repo=info".parse().unwrap()));
40+
.add_directive("samod=info".parse().unwrap())
41+
.add_directive("samod_core=info".parse().unwrap()));
4142
let file_layer = tracing_subscriber::fmt::layer()
4243
.with_line_number(true)
4344
.with_ansi(false)
4445
.with_writer(non_blocking_file_writer.clone())
4546
.with_filter(EnvFilter::new("info")
4647
.add_directive("patchwork_rust_core=trace".parse().unwrap())
47-
.add_directive("automerge_repo=debug".parse().unwrap()));
48+
.add_directive("samod=info".parse().unwrap())
49+
.add_directive("samod_core=info".parse().unwrap()));
4850
if let Err(e) = tracing_subscriber::registry()
4951
// stdout writer
5052
.with(stdout_layer)

rust/src/helpers/utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{diff::differ::ProjectDiff, helpers::{branch::BranchState, doc_utils:
66
use automerge::{
77
Automerge, Change, ChangeHash, Patch, PatchLog, ROOT, ReadDoc, transaction::{CommitOptions, Transaction}
88
};
9-
use automerge_repo::{DocHandle, DocumentId};
9+
use samod::{DocHandle, DocumentId};
1010
use chrono::{DateTime, Local};
1111
use serde::{Deserialize, Serialize};
1212

@@ -73,7 +73,7 @@ pub(crate) fn get_linked_docs_of_branch(
7373
branch_doc_handle: &DocHandle,
7474
) -> HashMap<String, DocumentId> {
7575
// Collect all linked doc IDs from this branch
76-
branch_doc_handle.with_doc(|d| {
76+
branch_doc_handle.with_document(|d| {
7777
let files = match d.get_obj_id(ROOT, "files") {
7878
Some(files) => files,
7979
None => {
@@ -215,6 +215,7 @@ impl From<&Change> for CommitInfo {
215215
}
216216
}
217217

218+
218219
#[derive(Debug)]
219220
pub struct BranchWrapper {
220221
pub state: BranchState,

rust/src/interop/godot_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22
use std::{fmt::Display};
33
use automerge::{ChangeHash};
4-
use automerge_repo::{DocumentId};
4+
use samod::{DocumentId};
55
use godot::meta::{ArgPassing, ByValue, GodotType, ToArg};
66
use godot::{prelude::*, meta::ToGodot, meta::GodotConvert};
77
use crate::fs::file_utils::FileContent;

rust/src/interop/godot_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::project::project::{Project, GodotProjectSignal};
55
use automerge::ChangeHash;
66
use godot::classes::editor_plugin::DockSlot;
77
use ::safer_ffi::prelude::*;
8-
use automerge_repo::{DocumentId};
8+
use samod::{DocumentId};
99
use godot::classes::resource_loader::CacheMode;
1010
use godot::classes::{ConfirmationDialog, Control};
1111
use godot::classes::EditorInterface;

rust/src/parser/godot_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ pub fn parse_scene(source: &String) -> Result<GodotScene, String> {
715715
// Check if node has a patchwork_id in metadata
716716
let node_id_num = match heading.get("unique_id") {
717717
Some(unique_id) => unique_id.parse::<i32>().unwrap_or(UNIQUE_SCENE_ID_UNASSIGNED),
718-
None => return Err("Missing required 'unique_id' attribute in node section".to_string())
718+
None => -1
719719
};
720720
parsed_node_ids.insert(node_id_num);
721721

0 commit comments

Comments
 (0)