editor_vcs_interface.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.h"
  33. #include "core/ustring.h"
  34. #include "scene/gui/panel_container.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(Dictionary p_diff_line);
  87. DiffHunk _convert_diff_hunk(Dictionary p_diff_hunk);
  88. DiffFile _convert_diff_file(Dictionary p_diff_file);
  89. Commit _convert_commit(Dictionary p_commit);
  90. StatusFile _convert_status_file(Dictionary p_status_file);
  91. public:
  92. static EditorVCSInterface *get_singleton();
  93. static void set_singleton(EditorVCSInterface *p_singleton);
  94. // Proxy functions to the editor for use
  95. bool initialize(String p_project_path);
  96. 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);
  97. List<StatusFile> get_modified_files_data();
  98. void stage_file(String p_file_path);
  99. void unstage_file(String p_file_path);
  100. void discard_file(String p_file_path);
  101. void commit(String p_msg);
  102. List<DiffFile> get_diff(String p_identifier, TreeArea p_area);
  103. bool shut_down();
  104. String get_vcs_name();
  105. List<Commit> get_previous_commits(int p_max_commits);
  106. List<String> get_branch_list();
  107. List<String> get_remotes();
  108. void create_branch(String p_branch_name);
  109. void remove_branch(String p_branch_name);
  110. void create_remote(String p_remote_name, String p_remote_url);
  111. void remove_remote(String p_remote_name);
  112. String get_current_branch_name();
  113. bool checkout_branch(String p_branch_name);
  114. void pull(String p_remote);
  115. void push(String p_remote, bool p_force);
  116. void fetch(String p_remote);
  117. List<DiffHunk> get_line_diff(String p_file_path, String p_text);
  118. // Helper functions to create and convert Dictionary into data structures
  119. Dictionary create_diff_line(int p_new_line_no, int p_old_line_no, String p_content, String p_status);
  120. Dictionary create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines);
  121. Dictionary create_diff_file(String p_new_file, String p_old_file);
  122. Dictionary create_commit(String p_msg, String p_author, String p_id, int64_t p_unix_timestamp, int64_t p_offset_minutes);
  123. Dictionary create_status_file(String p_file_path, ChangeType p_change, TreeArea p_area);
  124. Dictionary add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, Array p_line_diffs);
  125. Dictionary add_diff_hunks_into_diff_file(Dictionary p_diff_file, Array p_diff_hunks);
  126. void popup_error(String p_msg);
  127. };
  128. VARIANT_ENUM_CAST(EditorVCSInterface::ChangeType);
  129. VARIANT_ENUM_CAST(EditorVCSInterface::TreeArea);
  130. #endif // EDITOR_VCS_INTERFACE_H