editor_vcs_interface.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. #ifndef EDITOR_VCS_INTERFACE_H
  31. #define EDITOR_VCS_INTERFACE_H
  32. #include "core/object/class_db.h"
  33. #include "core/object/gdvirtual.gen.inc"
  34. #include "core/string/ustring.h"
  35. #include "core/variant/type_info.h"
  36. #include "core/variant/typed_array.h"
  37. class EditorVCSInterface : public Object {
  38. GDCLASS(EditorVCSInterface, Object)
  39. public:
  40. enum ChangeType {
  41. CHANGE_TYPE_NEW = 0,
  42. CHANGE_TYPE_MODIFIED = 1,
  43. CHANGE_TYPE_RENAMED = 2,
  44. CHANGE_TYPE_DELETED = 3,
  45. CHANGE_TYPE_TYPECHANGE = 4,
  46. CHANGE_TYPE_UNMERGED = 5
  47. };
  48. enum TreeArea {
  49. TREE_AREA_COMMIT = 0,
  50. TREE_AREA_STAGED = 1,
  51. TREE_AREA_UNSTAGED = 2
  52. };
  53. struct DiffLine {
  54. int new_line_no;
  55. int old_line_no;
  56. String content;
  57. String status;
  58. String old_text;
  59. String new_text;
  60. };
  61. struct DiffHunk {
  62. int new_start;
  63. int old_start;
  64. int new_lines;
  65. int old_lines;
  66. List<DiffLine> diff_lines;
  67. };
  68. struct DiffFile {
  69. String new_file;
  70. String old_file;
  71. List<DiffHunk> diff_hunks;
  72. };
  73. struct Commit {
  74. String author;
  75. String msg;
  76. String id;
  77. int64_t unix_timestamp;
  78. int64_t offset_minutes;
  79. };
  80. struct StatusFile {
  81. TreeArea area;
  82. ChangeType change_type;
  83. String file_path;
  84. };
  85. protected:
  86. static EditorVCSInterface *singleton;
  87. static void _bind_methods();
  88. DiffLine _convert_diff_line(const Dictionary &p_diff_line);
  89. DiffHunk _convert_diff_hunk(const Dictionary &p_diff_hunk);
  90. DiffFile _convert_diff_file(const Dictionary &p_diff_file);
  91. Commit _convert_commit(const Dictionary &p_commit);
  92. StatusFile _convert_status_file(const Dictionary &p_status_file);
  93. // Proxy endpoints for extensions to implement
  94. GDVIRTUAL1R_REQUIRED(bool, _initialize, String);
  95. GDVIRTUAL5_REQUIRED(_set_credentials, String, String, String, String, String);
  96. GDVIRTUAL0R_REQUIRED(TypedArray<Dictionary>, _get_modified_files_data);
  97. GDVIRTUAL1_REQUIRED(_stage_file, String);
  98. GDVIRTUAL1_REQUIRED(_unstage_file, String);
  99. GDVIRTUAL1_REQUIRED(_discard_file, String);
  100. GDVIRTUAL1_REQUIRED(_commit, String);
  101. GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_diff, String, int);
  102. GDVIRTUAL0R_REQUIRED(bool, _shut_down);
  103. GDVIRTUAL0R_REQUIRED(String, _get_vcs_name);
  104. GDVIRTUAL1R_REQUIRED(TypedArray<Dictionary>, _get_previous_commits, int);
  105. GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_branch_list);
  106. GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_remotes);
  107. GDVIRTUAL1_REQUIRED(_create_branch, String);
  108. GDVIRTUAL1_REQUIRED(_remove_branch, String);
  109. GDVIRTUAL2_REQUIRED(_create_remote, String, String);
  110. GDVIRTUAL1_REQUIRED(_remove_remote, String);
  111. GDVIRTUAL0R_REQUIRED(String, _get_current_branch_name);
  112. GDVIRTUAL1R_REQUIRED(bool, _checkout_branch, String);
  113. GDVIRTUAL1_REQUIRED(_pull, String);
  114. GDVIRTUAL2_REQUIRED(_push, String, bool);
  115. GDVIRTUAL1_REQUIRED(_fetch, String);
  116. GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_line_diff, String, String);
  117. public:
  118. static EditorVCSInterface *get_singleton();
  119. static void set_singleton(EditorVCSInterface *p_singleton);
  120. enum class VCSMetadata {
  121. NONE,
  122. GIT,
  123. };
  124. static void create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir);
  125. // Proxies to the editor for use
  126. bool initialize(const String &p_project_path);
  127. 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);
  128. List<StatusFile> get_modified_files_data();
  129. void stage_file(const String &p_file_path);
  130. void unstage_file(const String &p_file_path);
  131. void discard_file(const String &p_file_path);
  132. void commit(const String &p_msg);
  133. List<DiffFile> get_diff(const String &p_identifier, TreeArea p_area);
  134. bool shut_down();
  135. String get_vcs_name();
  136. List<Commit> get_previous_commits(int p_max_commits);
  137. List<String> get_branch_list();
  138. List<String> get_remotes();
  139. void create_branch(const String &p_branch_name);
  140. void remove_branch(const String &p_branch_name);
  141. void create_remote(const String &p_remote_name, const String &p_remote_url);
  142. void remove_remote(const String &p_remote_name);
  143. String get_current_branch_name();
  144. bool checkout_branch(const String &p_branch_name);
  145. void pull(const String &p_remote);
  146. void push(const String &p_remote, bool p_force);
  147. void fetch(const String &p_remote);
  148. List<DiffHunk> get_line_diff(const String &p_file_path, const String &p_text);
  149. // Helper functions to create and convert Dictionary into data structures
  150. Dictionary create_diff_line(int p_new_line_no, int p_old_line_no, const String &p_content, const String &p_status);
  151. Dictionary create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines);
  152. Dictionary create_diff_file(const String &p_new_file, const String &p_old_file);
  153. 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);
  154. Dictionary create_status_file(const String &p_file_path, ChangeType p_change, TreeArea p_area);
  155. Dictionary add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, TypedArray<Dictionary> p_line_diffs);
  156. Dictionary add_diff_hunks_into_diff_file(Dictionary p_diff_file, TypedArray<Dictionary> p_diff_hunks);
  157. void popup_error(const String &p_msg);
  158. };
  159. VARIANT_ENUM_CAST(EditorVCSInterface::ChangeType);
  160. VARIANT_ENUM_CAST(EditorVCSInterface::TreeArea);
  161. #endif // EDITOR_VCS_INTERFACE_H