Debian Codegraph @

editor/version_control/editor_vcs_interface.h

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_vcs_interface.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/object/gdvirtual.gen.inc"
34 #include "core/string/ustring.h"
35 #include "core/variant/typed_array.h"
36
37 class EditorVCSInterface : public Object {
38 GDCLASS(EditorVCSInterface, Object)
39
40 public:
41 enum ChangeType {
42 CHANGE_TYPE_NEW = 0,
43 CHANGE_TYPE_MODIFIED = 1,
44 CHANGE_TYPE_RENAMED = 2,
45 CHANGE_TYPE_DELETED = 3,
46 CHANGE_TYPE_TYPECHANGE = 4,
47 CHANGE_TYPE_UNMERGED = 5
48 };
49
50 enum TreeArea {
51 TREE_AREA_COMMIT = 0,
52 TREE_AREA_STAGED = 1,
53 TREE_AREA_UNSTAGED = 2
54 };
55
56 struct DiffLine {
57 int new_line_no;
58 int old_line_no;
59 String content;
60 String status;
61
62 String old_text;
63 String new_text;
64 };
65
66 struct DiffHunk {
67 int new_start;
68 int old_start;
69 int new_lines;
70 int old_lines;
71 List<DiffLine> diff_lines;
72 };
73
74 struct DiffFile {
75 String new_file;
76 String old_file;
77 List<DiffHunk> diff_hunks;
78 };
79
80 struct Commit {
81 String author;
82 String msg;
83 String id;
84 int64_t unix_timestamp;
85 int64_t offset_minutes;
86 };
87
88 struct StatusFile {
89 TreeArea area;
90 ChangeType change_type;
91 String file_path;
92 };
93
94 protected:
95 static EditorVCSInterface *singleton;
96
97 static void _bind_methods();
98
99 DiffLine _convert_diff_line(const Dictionary &p_diff_line);
100 DiffHunk _convert_diff_hunk(const Dictionary &p_diff_hunk);
101 DiffFile _convert_diff_file(const Dictionary &p_diff_file);
102 Commit _convert_commit(const Dictionary &p_commit);
103 StatusFile _convert_status_file(const Dictionary &p_status_file);
104
105 // Proxy endpoints for extensions to implement
106 GDVIRTUAL1R_REQUIRED(bool, _initialize, String);
107 GDVIRTUAL5_REQUIRED(_set_credentials, String, String, String, String, String);
108 GDVIRTUAL0R_REQUIRED(TypedArray<Dictionary>, _get_modified_files_data);
109 GDVIRTUAL1_REQUIRED(_stage_file, String);
110 GDVIRTUAL1_REQUIRED(_unstage_file, String);
111 GDVIRTUAL1_REQUIRED(_discard_file, String);
112 GDVIRTUAL1_REQUIRED(_commit, String);
113 GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_diff, String, int);
114 GDVIRTUAL0R_REQUIRED(bool, _shut_down);
115 GDVIRTUAL0R_REQUIRED(String, _get_vcs_name);
116 GDVIRTUAL1R_REQUIRED(TypedArray<Dictionary>, _get_previous_commits, int);
117 GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_branch_list);
118 GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_remotes);
119 GDVIRTUAL1_REQUIRED(_create_branch, String);
120 GDVIRTUAL1_REQUIRED(_remove_branch, String);
121 GDVIRTUAL2_REQUIRED(_create_remote, String, String);
122 GDVIRTUAL1_REQUIRED(_remove_remote, String);
123 GDVIRTUAL0R_REQUIRED(String, _get_current_branch_name);
124 GDVIRTUAL1R_REQUIRED(bool, _checkout_branch, String);
125 GDVIRTUAL1_REQUIRED(_pull, String);
126 GDVIRTUAL2_REQUIRED(_push, String, bool);
127 GDVIRTUAL1_REQUIRED(_fetch, String);
128 GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_line_diff, String, String);
129
130 public:
131 static EditorVCSInterface *get_singleton();
132 static void set_singleton(EditorVCSInterface *p_singleton);
133
134 enum class VCSMetadata {
135 NONE,
136 GIT,
137 };
138 static void create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir);
139
140 // Proxies to the editor for use
141 bool initialize(const String &p_project_path);
142 void set_credentials(const String &p_username, const String &p_password, const String &p_ssh_public_key_path, const String &p_ssh_private_key_path, const String &p_ssh_passphrase);
143 List<StatusFile> get_modified_files_data();
144 void stage_file(const String &p_file_path);
145 void unstage_file(const String &p_file_path);
146 void discard_file(const String &p_file_path);
147 void commit(const String &p_msg);
148 List<DiffFile> get_diff(const String &p_identifier, TreeArea p_area);
149 bool shut_down();
150 String get_vcs_name();
151 List<Commit> get_previous_commits(int p_max_commits);
152 List<String> get_branch_list();
153 List<String> get_remotes();
154 void create_branch(const String &p_branch_name);
155 void remove_branch(const String &p_branch_name);
156 void create_remote(const String &p_remote_name, const String &p_remote_url);
157 void remove_remote(const String &p_remote_name);
158 String get_current_branch_name();
159 bool checkout_branch(const String &p_branch_name);
160 void pull(const String &p_remote);
161 void push(const String &p_remote, bool p_force);
162 void fetch(const String &p_remote);
163 List<DiffHunk> get_line_diff(const String &p_file_path, const String &p_text);
164
165 // Helper functions to create and convert Dictionary into data structures
166 Dictionary create_diff_line(int p_new_line_no, int p_old_line_no, const String &p_content, const String &p_status);
167 Dictionary create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines);
168 Dictionary create_diff_file(const String &p_new_file, const String &p_old_file);
169 Dictionary create_commit(const String &p_msg, const String &p_author, const String &p_id, int64_t p_unix_timestamp, int64_t p_offset_minutes);
170 Dictionary create_status_file(const String &p_file_path, ChangeType p_change, TreeArea p_area);
171 Dictionary add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, TypedArray<Dictionary> p_line_diffs);
172 Dictionary add_diff_hunks_into_diff_file(Dictionary p_diff_file, TypedArray<Dictionary> p_diff_hunks);
173
174 void popup_error(const String &p_msg);
175 };
176
177 VARIANT_ENUM_CAST(EditorVCSInterface::ChangeType);
178 VARIANT_ENUM_CAST(EditorVCSInterface::TreeArea);