| 634 | } |
| 635 | |
| 636 | Ref<DiffResult> DiffResult::get_diff(Dictionary changed_files_dict) { |
| 637 | Ref<DiffResult> result; |
| 638 | result.instantiate(); |
| 639 | Array files = changed_files_dict["files"]; |
| 640 | for (const auto &d : files) { |
| 641 | Dictionary dict = d; |
| 642 | if (dict.size() == 0) { |
| 643 | continue; |
| 644 | } |
| 645 | String change_type = dict["change"]; |
| 646 | String path = dict["path"]; |
| 647 | auto old_content = dict["old_content"]; |
| 648 | auto new_content = dict["new_content"]; |
| 649 | auto structured_changes = dict["scene_changes"]; |
| 650 | if (change_type == "modified") { |
| 651 | // check both the old and the new content to see what the file sizes are |
| 652 | auto faold = FileAccess::open(old_content, FileAccess::READ); |
| 653 | auto fanew = FileAccess::open(new_content, FileAccess::READ); |
| 654 | if (faold.is_null() || fanew.is_null()) { |
| 655 | continue; |
| 656 | } |
| 657 | auto old_size = faold->get_length(); |
| 658 | auto new_size = fanew->get_length(); |
| 659 | if (old_size < 4 && new_size < 4) { |
| 660 | ERR_FAIL_COND_V(old_size < 4 && new_size < 4, result); |
| 661 | } |
| 662 | if (old_size < 4) { |
| 663 | change_type = "added"; |
| 664 | } else if (new_size < 4) { |
| 665 | change_type = "deleted"; |
| 666 | } else { |
| 667 | auto diff = FileDiffResult::get_file_diff(old_content, new_content, structured_changes); |
| 668 | if (diff.is_null()) { |
| 669 | continue; |
| 670 | } |
| 671 | result->set_file_diff(path, diff); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | if (change_type == "added" || change_type == "deleted") { |
| 676 | Ref<FileDiffResult> file_diff; |
| 677 | file_diff.instantiate(); |
| 678 | file_diff->set_type(change_type); |
| 679 | Error error = OK; |
| 680 | if (change_type == "added") { |
| 681 | file_diff->set_res_new(ResourceLoader::load(new_content, "", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP, &error)); |
| 682 | } else { |
| 683 | file_diff->set_res_old(ResourceLoader::load(old_content, "", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP, &error)); |
| 684 | } |
| 685 | if (error != OK) { |
| 686 | print_error("Failed to load resource at path " + path); |
| 687 | continue; |
| 688 | } |
| 689 | result->set_file_diff(path, file_diff); |
| 690 | } |
| 691 | } |
| 692 | return result; |
| 693 | } |
nothing calls this directly
no test coverage detected