From 4656ea8977ae7cb8c49df158566b663a6c5ab071 Mon Sep 17 00:00:00 2001 From: Twarit Waikar Date: Tue, 14 Jun 2022 00:17:40 +0530 Subject: VCS: Port Godot 3.5's VCS features to GDExtension --- editor/editor_vcs_interface.cpp | 381 +++++- editor/editor_vcs_interface.h | 143 +- editor/plugins/script_editor_plugin.cpp | 92 +- editor/plugins/script_editor_plugin.h | 2 +- editor/plugins/version_control_editor_plugin.cpp | 1547 ++++++++++++++++++---- editor/plugins/version_control_editor_plugin.h | 183 ++- 6 files changed, 1851 insertions(+), 497 deletions(-) diff --git a/editor/editor_vcs_interface.cpp b/editor/editor_vcs_interface.cpp index 53cc8d5b22..521e23ee55 100644 --- a/editor/editor_vcs_interface.cpp +++ b/editor/editor_vcs_interface.cpp @@ -30,132 +30,371 @@ #include "editor_vcs_interface.h" +#include "editor_node.h" + +#define UNIMPLEMENTED() ERR_PRINT(TTR("Unimplemented virtual function in EditorVCSInterface based node: ") + __func__) + EditorVCSInterface *EditorVCSInterface::singleton = nullptr; -void EditorVCSInterface::_bind_methods() { - // Proxy end points that act as fallbacks to unavailability of a function in the VCS addon - ClassDB::bind_method(D_METHOD("_initialize", "project_root_path"), &EditorVCSInterface::_initialize); - ClassDB::bind_method(D_METHOD("_is_vcs_initialized"), &EditorVCSInterface::_is_vcs_initialized); - ClassDB::bind_method(D_METHOD("_get_vcs_name"), &EditorVCSInterface::_get_vcs_name); - ClassDB::bind_method(D_METHOD("_shut_down"), &EditorVCSInterface::_shut_down); - ClassDB::bind_method(D_METHOD("_get_project_name"), &EditorVCSInterface::_get_project_name); - ClassDB::bind_method(D_METHOD("_get_modified_files_data"), &EditorVCSInterface::_get_modified_files_data); - ClassDB::bind_method(D_METHOD("_commit", "msg"), &EditorVCSInterface::_commit); - ClassDB::bind_method(D_METHOD("_get_file_diff", "file_path"), &EditorVCSInterface::_get_file_diff); - ClassDB::bind_method(D_METHOD("_stage_file", "file_path"), &EditorVCSInterface::_stage_file); - ClassDB::bind_method(D_METHOD("_unstage_file", "file_path"), &EditorVCSInterface::_unstage_file); +void EditorVCSInterface::popup_error(String p_msg) { + // TRANSLATORS: %s refers to the name of a version control system (e.g. "Git"). + EditorNode::get_singleton()->show_warning(p_msg.strip_edges(), vformat(TTR("%s Error"), get_vcs_name())); +} - ClassDB::bind_method(D_METHOD("is_addon_ready"), &EditorVCSInterface::is_addon_ready); +bool EditorVCSInterface::initialize(String p_project_path) { + bool result = false; + if (!GDVIRTUAL_CALL(_initialize, p_project_path, result)) { + UNIMPLEMENTED(); + return false; + } + return result; +} - // API methods that redirect calls to the proxy end points - ClassDB::bind_method(D_METHOD("initialize", "project_root_path"), &EditorVCSInterface::initialize); - ClassDB::bind_method(D_METHOD("is_vcs_initialized"), &EditorVCSInterface::is_vcs_initialized); - ClassDB::bind_method(D_METHOD("get_modified_files_data"), &EditorVCSInterface::get_modified_files_data); - ClassDB::bind_method(D_METHOD("stage_file", "file_path"), &EditorVCSInterface::stage_file); - ClassDB::bind_method(D_METHOD("unstage_file", "file_path"), &EditorVCSInterface::unstage_file); - ClassDB::bind_method(D_METHOD("commit", "msg"), &EditorVCSInterface::commit); - ClassDB::bind_method(D_METHOD("get_file_diff", "file_path"), &EditorVCSInterface::get_file_diff); - ClassDB::bind_method(D_METHOD("shut_down"), &EditorVCSInterface::shut_down); - ClassDB::bind_method(D_METHOD("get_project_name"), &EditorVCSInterface::get_project_name); - ClassDB::bind_method(D_METHOD("get_vcs_name"), &EditorVCSInterface::get_vcs_name); +void EditorVCSInterface::set_credentials(String p_username, String p_password, String p_ssh_public_key, String p_ssh_private_key, String p_ssh_passphrase) { + if (!GDVIRTUAL_CALL(_set_credentials, p_username, p_password, p_ssh_public_key, p_ssh_private_key, p_ssh_passphrase)) { + UNIMPLEMENTED(); + } } -bool EditorVCSInterface::_initialize(String p_project_root_path) { - WARN_PRINT("Selected VCS addon does not implement an initialization function. This warning will be suppressed."); - return true; +List EditorVCSInterface::get_remotes() { + Array result; + if (!GDVIRTUAL_CALL(_get_remotes, result)) { + UNIMPLEMENTED(); + return {}; + } + + List remotes; + for (int i = 0; i < result.size(); i++) { + remotes.push_back(result[i]); + } + return remotes; } -bool EditorVCSInterface::_is_vcs_initialized() { - return false; +List EditorVCSInterface::get_modified_files_data() { + Array result; + if (!GDVIRTUAL_CALL(_get_modified_files_data, result)) { + UNIMPLEMENTED(); + return {}; + } + + List status_files; + for (int i = 0; i < result.size(); i++) { + status_files.push_back(_convert_status_file(result[i])); + } + return status_files; } -Dictionary EditorVCSInterface::_get_modified_files_data() { - return Dictionary(); +void EditorVCSInterface::stage_file(String p_file_path) { + if (!GDVIRTUAL_CALL(_stage_file, p_file_path)) { + UNIMPLEMENTED(); + } } -void EditorVCSInterface::_stage_file(String p_file_path) { +void EditorVCSInterface::unstage_file(String p_file_path) { + if (!GDVIRTUAL_CALL(_unstage_file, p_file_path)) { + UNIMPLEMENTED(); + } } -void EditorVCSInterface::_unstage_file(String p_file_path) { +void EditorVCSInterface::discard_file(String p_file_path) { + if (!GDVIRTUAL_CALL(_discard_file, p_file_path)) { + UNIMPLEMENTED(); + } } -void EditorVCSInterface::_commit(String p_msg) { +void EditorVCSInterface::commit(String p_msg) { + if (!GDVIRTUAL_CALL(_commit, p_msg)) { + UNIMPLEMENTED(); + } } -TypedArray EditorVCSInterface::_get_file_diff(String p_file_path) { - return TypedArray(); +List EditorVCSInterface::get_diff(String p_identifier, TreeArea p_area) { + TypedArray result; + if (!GDVIRTUAL_CALL(_get_diff, p_identifier, int(p_area), result)) { + UNIMPLEMENTED(); + return {}; + } + + List diff_files; + for (int i = 0; i < result.size(); i++) { + diff_files.push_back(_convert_diff_file(result[i])); + } + return diff_files; } -bool EditorVCSInterface::_shut_down() { - return false; +List EditorVCSInterface::get_previous_commits(int p_max_commits) { + Array result; + if (!GDVIRTUAL_CALL(_get_previous_commits, p_max_commits, result)) { + UNIMPLEMENTED(); + return {}; + } + + List commits; + for (int i = 0; i < result.size(); i++) { + commits.push_back(_convert_commit(result[i])); + } + return commits; } -String EditorVCSInterface::_get_project_name() { - return String(); +List EditorVCSInterface::get_branch_list() { + Array result; + if (!GDVIRTUAL_CALL(_get_branch_list, result)) { + UNIMPLEMENTED(); + return {}; + } + + List branch_list; + for (int i = 0; i < result.size(); i++) { + branch_list.push_back(result[i]); + } + return branch_list; } -String EditorVCSInterface::_get_vcs_name() { - return ""; +void EditorVCSInterface::create_branch(String p_branch_name) { + if (!GDVIRTUAL_CALL(_create_branch, p_branch_name)) { + UNIMPLEMENTED(); + } } -bool EditorVCSInterface::initialize(String p_project_root_path) { - is_initialized = call("_initialize", p_project_root_path); - return is_initialized; +void EditorVCSInterface::create_remote(String p_remote_name, String p_remote_url) { + if (!GDVIRTUAL_CALL(_create_remote, p_remote_name, p_remote_url)) { + UNIMPLEMENTED(); + } } -bool EditorVCSInterface::is_vcs_initialized() { - return call("_is_vcs_initialized"); +void EditorVCSInterface::remove_branch(String p_branch_name) { + if (!GDVIRTUAL_CALL(_remove_branch, p_branch_name)) { + UNIMPLEMENTED(); + } } -Dictionary EditorVCSInterface::get_modified_files_data() { - return call("_get_modified_files_data"); +void EditorVCSInterface::remove_remote(String p_remote_name) { + if (!GDVIRTUAL_CALL(_remove_remote, p_remote_name)) { + UNIMPLEMENTED(); + } } -void EditorVCSInterface::stage_file(String p_file_path) { - if (is_addon_ready()) { - call("_stage_file", p_file_path); +String EditorVCSInterface::get_current_branch_name() { + String result; + if (!GDVIRTUAL_CALL(_get_current_branch_name, result)) { + UNIMPLEMENTED(); + return ""; } + return result; } -void EditorVCSInterface::unstage_file(String p_file_path) { - if (is_addon_ready()) { - call("_unstage_file", p_file_path); +bool EditorVCSInterface::checkout_branch(String p_branch_name) { + bool result = false; + if (!GDVIRTUAL_CALL(_checkout_branch, p_branch_name, result)) { + UNIMPLEMENTED(); } + return result; } -bool EditorVCSInterface::is_addon_ready() { - return is_initialized; +void EditorVCSInterface::pull(String p_remote) { + if (!GDVIRTUAL_CALL(_pull, p_remote)) { + UNIMPLEMENTED(); + } } -void EditorVCSInterface::commit(String p_msg) { - if (is_addon_ready()) { - call("_commit", p_msg); +void EditorVCSInterface::push(String p_remote, bool p_force) { + if (!GDVIRTUAL_CALL(_push, p_remote, p_force)) { + UNIMPLEMENTED(); } } -TypedArray EditorVCSInterface::get_file_diff(String p_file_path) { - if (is_addon_ready()) { - return call("_get_file_diff", p_file_path); +void EditorVCSInterface::fetch(String p_remote) { + if (!GDVIRTUAL_CALL(_fetch, p_remote)) { + UNIMPLEMENTED(); } - return TypedArray(); } -bool EditorVCSInterface::shut_down() { - return call("_shut_down"); +List EditorVCSInterface::get_line_diff(String p_file_path, String p_text) { + Array result; + if (!GDVIRTUAL_CALL(_get_line_diff, p_file_path, p_text, result)) { + UNIMPLEMENTED(); + return {}; + } + + List diff_hunks; + for (int i = 0; i < result.size(); i++) { + diff_hunks.push_back(_convert_diff_hunk(result[i])); + } + return diff_hunks; } -String EditorVCSInterface::get_project_name() { - return call("_get_project_name"); +bool EditorVCSInterface::shut_down() { + bool result = false; + if (!GDVIRTUAL_CALL(_shut_down, result)) { + UNIMPLEMENTED(); + return false; + } + return result; } String EditorVCSInterface::get_vcs_name() { - return call("_get_vcs_name"); + String result; + if (!GDVIRTUAL_CALL(_get_vcs_name, result)) { + UNIMPLEMENTED(); + return {}; + } + return result; +} + +Dictionary EditorVCSInterface::create_diff_line(int p_new_line_no, int p_old_line_no, String p_content, String p_status) { + Dictionary diff_line; + diff_line["new_line_no"] = p_new_line_no; + diff_line["old_line_no"] = p_old_line_no; + diff_line["content"] = p_content; + diff_line["status"] = p_status; + + return diff_line; +} + +Dictionary EditorVCSInterface::create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines) { + Dictionary diff_hunk; + diff_hunk["new_lines"] = p_new_lines; + diff_hunk["old_lines"] = p_old_lines; + diff_hunk["new_start"] = p_new_start; + diff_hunk["old_start"] = p_old_start; + diff_hunk["diff_lines"] = Array(); + return diff_hunk; +} + +Dictionary EditorVCSInterface::add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, Array p_line_diffs) { + p_diff_hunk["diff_lines"] = p_line_diffs; + return p_diff_hunk; +} + +Dictionary EditorVCSInterface::create_diff_file(String p_new_file, String p_old_file) { + Dictionary file_diff; + file_diff["new_file"] = p_new_file; + file_diff["old_file"] = p_old_file; + file_diff["diff_hunks"] = Array(); + return file_diff; +} + +Dictionary EditorVCSInterface::create_commit(String p_msg, String p_author, String p_id, int64_t p_unix_timestamp, int64_t p_offset_minutes) { + Dictionary commit_info; + commit_info["message"] = p_msg; + commit_info["author"] = p_author; + commit_info["unix_timestamp"] = p_unix_timestamp; + commit_info["offset_minutes"] = p_offset_minutes; + commit_info["id"] = p_id; + return commit_info; } -EditorVCSInterface::EditorVCSInterface() { +Dictionary EditorVCSInterface::add_diff_hunks_into_diff_file(Dictionary p_diff_file, Array p_diff_hunks) { + p_diff_file["diff_hunks"] = p_diff_hunks; + return p_diff_file; } -EditorVCSInterface::~EditorVCSInterface() { +Dictionary EditorVCSInterface::create_status_file(String p_file_path, ChangeType p_change, TreeArea p_area) { + Dictionary sf; + sf["file_path"] = p_file_path; + sf["change_type"] = p_change; + sf["area"] = p_area; + return sf; +} + +EditorVCSInterface::DiffLine EditorVCSInterface::_convert_diff_line(Dictionary p_diff_line) { + DiffLine d; + d.new_line_no = p_diff_line["new_line_no"]; + d.old_line_no = p_diff_line["old_line_no"]; + d.content = p_diff_line["content"]; + d.status = p_diff_line["status"]; + return d; +} + +EditorVCSInterface::DiffHunk EditorVCSInterface::_convert_diff_hunk(Dictionary p_diff_hunk) { + DiffHunk dh; + dh.new_lines = p_diff_hunk["new_lines"]; + dh.old_lines = p_diff_hunk["old_lines"]; + dh.new_start = p_diff_hunk["new_start"]; + dh.old_start = p_diff_hunk["old_start"]; + Array diff_lines = p_diff_hunk["diff_lines"]; + for (int i = 0; i < diff_lines.size(); i++) { + DiffLine dl = _convert_diff_line(diff_lines[i]); + dh.diff_lines.push_back(dl); + } + return dh; +} + +EditorVCSInterface::DiffFile EditorVCSInterface::_convert_diff_file(Dictionary p_diff_file) { + DiffFile df; + df.new_file = p_diff_file["new_file"]; + df.old_file = p_diff_file["old_file"]; + Array diff_hunks = p_diff_file["diff_hunks"]; + for (int i = 0; i < diff_hunks.size(); i++) { + DiffHunk dh = _convert_diff_hunk(diff_hunks[i]); + df.diff_hunks.push_back(dh); + } + return df; +} + +EditorVCSInterface::Commit EditorVCSInterface::_convert_commit(Dictionary p_commit) { + EditorVCSInterface::Commit c; + c.msg = p_commit["message"]; + c.author = p_commit["author"]; + c.unix_timestamp = p_commit["unix_timestamp"]; + c.offset_minutes = p_commit["offset_minutes"]; + c.id = p_commit["id"]; + return c; +} + +EditorVCSInterface::StatusFile EditorVCSInterface::_convert_status_file(Dictionary p_status_file) { + StatusFile sf; + sf.file_path = p_status_file["file_path"]; + sf.change_type = (ChangeType)(int)p_status_file["change_type"]; + sf.area = (TreeArea)(int)p_status_file["area"]; + return sf; +} + +void EditorVCSInterface::_bind_methods() { + // Proxy end points that implement the VCS specific operations that the editor demands. + GDVIRTUAL_BIND(_initialize, "project_path"); + GDVIRTUAL_BIND(_set_credentials, "username", "password", "ssh_public_key_path", "ssh_private_key_path", "ssh_passphrase"); + GDVIRTUAL_BIND(_get_modified_files_data); + GDVIRTUAL_BIND(_stage_file, "file_path"); + GDVIRTUAL_BIND(_unstage_file, "file_path"); + GDVIRTUAL_BIND(_discard_file, "file_path"); + GDVIRTUAL_BIND(_commit, "msg"); + GDVIRTUAL_BIND(_get_diff, "identifier", "area"); + GDVIRTUAL_BIND(_shut_down); + GDVIRTUAL_BIND(_get_vcs_name); + GDVIRTUAL_BIND(_get_previous_commits, "max_commits"); + GDVIRTUAL_BIND(_get_branch_list); + GDVIRTUAL_BIND(_get_remotes); + GDVIRTUAL_BIND(_create_branch, "branch_name"); + GDVIRTUAL_BIND(_remove_branch, "branch_name"); + GDVIRTUAL_BIND(_create_remote, "remote_name", "remote_url"); + GDVIRTUAL_BIND(_remove_remote, "remote_name"); + GDVIRTUAL_BIND(_get_current_branch_name); + GDVIRTUAL_BIND(_checkout_branch, "branch_name"); + GDVIRTUAL_BIND(_pull, "remote"); + GDVIRTUAL_BIND(_push, "remote", "force"); + GDVIRTUAL_BIND(_fetch, "remote"); + GDVIRTUAL_BIND(_get_line_diff, "file_path", "text"); + + ClassDB::bind_method(D_METHOD("create_diff_line", "new_line_no", "old_line_no", "content", "status"), &EditorVCSInterface::create_diff_line); + ClassDB::bind_method(D_METHOD("create_diff_hunk", "old_start", "new_start", "old_lines", "new_lines"), &EditorVCSInterface::create_diff_hunk); + ClassDB::bind_method(D_METHOD("create_diff_file", "new_file", "old_file"), &EditorVCSInterface::create_diff_file); + ClassDB::bind_method(D_METHOD("create_commit", "msg", "author", "id", "unix_timestamp", "offset_minutes"), &EditorVCSInterface::create_commit); + ClassDB::bind_method(D_METHOD("create_status_file", "file_path", "change_type", "area"), &EditorVCSInterface::create_status_file); + ClassDB::bind_method(D_METHOD("add_diff_hunks_into_diff_file", "diff_file", "diff_hunks"), &EditorVCSInterface::add_diff_hunks_into_diff_file); + ClassDB::bind_method(D_METHOD("add_line_diffs_into_diff_hunk", "diff_hunk", "line_diffs"), &EditorVCSInterface::add_line_diffs_into_diff_hunk); + ClassDB::bind_method(D_METHOD("popup_error", "msg"), &EditorVCSInterface::popup_error); + + BIND_ENUM_CONSTANT(CHANGE_TYPE_NEW); + BIND_ENUM_CONSTANT(CHANGE_TYPE_MODIFIED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_RENAMED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_DELETED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_TYPECHANGE); + BIND_ENUM_CONSTANT(CHANGE_TYPE_UNMERGED); + + BIND_ENUM_CONSTANT(TREE_AREA_COMMIT); + BIND_ENUM_CONSTANT(TREE_AREA_STAGED); + BIND_ENUM_CONSTANT(TREE_AREA_UNSTAGED); } EditorVCSInterface *EditorVCSInterface::get_singleton() { diff --git a/editor/editor_vcs_interface.h b/editor/editor_vcs_interface.h index d6d7ffa0e9..d9aee64adb 100644 --- a/editor/editor_vcs_interface.h +++ b/editor/editor_vcs_interface.h @@ -32,30 +32,103 @@ #define EDITOR_VCS_INTERFACE_H #include "core/object/class_db.h" +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language_extension.h" #include "core/string/ustring.h" -#include "scene/gui/panel_container.h" +#include "core/variant/type_info.h" class EditorVCSInterface : public Object { GDCLASS(EditorVCSInterface, Object) - bool is_initialized = false; +public: + enum ChangeType { + CHANGE_TYPE_NEW = 0, + CHANGE_TYPE_MODIFIED = 1, + CHANGE_TYPE_RENAMED = 2, + CHANGE_TYPE_DELETED = 3, + CHANGE_TYPE_TYPECHANGE = 4, + CHANGE_TYPE_UNMERGED = 5 + }; + + enum TreeArea { + TREE_AREA_COMMIT = 0, + TREE_AREA_STAGED = 1, + TREE_AREA_UNSTAGED = 2 + }; + + struct DiffLine { + int new_line_no; + int old_line_no; + String content; + String status; + + String old_text; + String new_text; + }; + + struct DiffHunk { + int new_start; + int old_start; + int new_lines; + int old_lines; + List diff_lines; + }; + + struct DiffFile { + String new_file; + String old_file; + List diff_hunks; + }; + + struct Commit { + String author; + String msg; + String id; + int64_t unix_timestamp; + int64_t offset_minutes; + }; + + struct StatusFile { + TreeArea area; + ChangeType change_type; + String file_path; + }; protected: static EditorVCSInterface *singleton; static void _bind_methods(); - // Implemented by addons as end points for the proxy functions - virtual bool _initialize(String p_project_root_path); - virtual bool _is_vcs_initialized(); - virtual Dictionary _get_modified_files_data(); - virtual void _stage_file(String p_file_path); - virtual void _unstage_file(String p_file_path); - virtual void _commit(String p_msg); - virtual TypedArray _get_file_diff(String p_file_path); - virtual bool _shut_down(); - virtual String _get_project_name(); - virtual String _get_vcs_name(); + DiffLine _convert_diff_line(Dictionary p_diff_line); + DiffHunk _convert_diff_hunk(Dictionary p_diff_hunk); + DiffFile _convert_diff_file(Dictionary p_diff_file); + Commit _convert_commit(Dictionary p_commit); + StatusFile _convert_status_file(Dictionary p_status_file); + + // Proxy endpoints for extensions to implement + GDVIRTUAL1R(bool, _initialize, String); + GDVIRTUAL5(_set_credentials, String, String, String, String, String); + GDVIRTUAL0R(Array, _get_modified_files_data); + GDVIRTUAL1(_stage_file, String); + GDVIRTUAL1(_unstage_file, String); + GDVIRTUAL1(_discard_file, String); + GDVIRTUAL1(_commit, String); + GDVIRTUAL2R(TypedArray, _get_diff, String, int); + GDVIRTUAL0R(bool, _shut_down); + GDVIRTUAL0R(String, _get_vcs_name); + GDVIRTUAL1R(Array, _get_previous_commits, int); + GDVIRTUAL0R(Array, _get_branch_list); + GDVIRTUAL0R(Array, _get_remotes); + GDVIRTUAL1(_create_branch, String); + GDVIRTUAL1(_remove_branch, String); + GDVIRTUAL2(_create_remote, String, String); + GDVIRTUAL1(_remove_remote, String); + GDVIRTUAL0R(String, _get_current_branch_name); + GDVIRTUAL1R(bool, _checkout_branch, String); + GDVIRTUAL1(_pull, String); + GDVIRTUAL2(_push, String, bool); + GDVIRTUAL1(_fetch, String); + GDVIRTUAL2R(Array, _get_line_diff, String, String); public: static EditorVCSInterface *get_singleton(); @@ -67,22 +140,44 @@ public: }; static void create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir); - bool is_addon_ready(); - - // Proxy functions to the editor for use - bool initialize(String p_project_root_path); - bool is_vcs_initialized(); - Dictionary get_modified_files_data(); + // Proxies to the editor for use + bool initialize(String p_project_path); + void set_credentials(String p_username, String p_password, String p_ssh_public_key_path, String p_ssh_private_key_path, String p_ssh_passphrase); + List get_modified_files_data(); void stage_file(String p_file_path); void unstage_file(String p_file_path); + void discard_file(String p_file_path); void commit(String p_msg); - TypedArray get_file_diff(String p_file_path); + List get_diff(String p_identifier, TreeArea p_area); bool shut_down(); - String get_project_name(); String get_vcs_name(); + List get_previous_commits(int p_max_commits); + List get_branch_list(); + List get_remotes(); + void create_branch(String p_branch_name); + void remove_branch(String p_branch_name); + void create_remote(String p_remote_name, String p_remote_url); + void remove_remote(String p_remote_name); + String get_current_branch_name(); + bool checkout_branch(String p_branch_name); + void pull(String p_remote); + void push(String p_remote, bool p_force); + void fetch(String p_remote); + List get_line_diff(String p_file_path, String p_text); - EditorVCSInterface(); - virtual ~EditorVCSInterface(); + // Helper functions to create and convert Dictionary into data structures + Dictionary create_diff_line(int p_new_line_no, int p_old_line_no, String p_content, String p_status); + Dictionary create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines); + Dictionary create_diff_file(String p_new_file, String p_old_file); + Dictionary create_commit(String p_msg, String p_author, String p_id, int64_t p_unix_timestamp, int64_t p_offset_minutes); + Dictionary create_status_file(String p_file_path, ChangeType p_change, TreeArea p_area); + Dictionary add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, Array p_line_diffs); + Dictionary add_diff_hunks_into_diff_file(Dictionary p_diff_file, Array p_diff_hunks); + + void popup_error(String p_msg); }; -#endif // EDITOR_VCS_INTERFACE_H +VARIANT_ENUM_CAST(EditorVCSInterface::ChangeType); +VARIANT_ENUM_CAST(EditorVCSInterface::TreeArea); + +#endif // !EDITOR_VCS_INTERFACE_H diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index aa1d630372..ad114e022f 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -940,50 +940,6 @@ void ScriptEditor::_resave_scripts(const String &p_str) { disk_changed->hide(); } -void ScriptEditor::_reload_scripts() { - for (int i = 0; i < tab_container->get_tab_count(); i++) { - ScriptEditorBase *se = Object::cast_to(tab_container->get_tab_control(i)); - if (!se) { - continue; - } - - Ref edited_res = se->get_edited_resource(); - - if (edited_res->is_built_in()) { - continue; //internal script, who cares - } - - uint64_t last_date = edited_res->get_last_modified_time(); - uint64_t date = FileAccess::get_modified_time(edited_res->get_path()); - - if (last_date == date) { - continue; - } - - Ref