editor_vcs_interface.h 7.3 KB

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