Process the list of diffs for every file from the result of "git show". * Caveats: * - changes in binary files can be ignored; * - if a line content begins with '+' or '-' it will be skipped * it means that if you store diffs in repository and "git show" will display diff-of-diff for you, * it won't be processed correctly; * - we expect some specific format of the diff; but it may
| 878 | * - non-ASCII file names are not processed correctly (they will not be found and will be ignored). |
| 879 | */ |
| 880 | void processDiffs( |
| 881 | ReadBuffer & in, |
| 882 | std::optional<size_t> size_limit, |
| 883 | Commit & commit, |
| 884 | CommitDiff & file_changes) |
| 885 | { |
| 886 | std::string old_file_path; |
| 887 | std::string new_file_path; |
| 888 | FileDiff * file_change_and_line_changes = nullptr; |
| 889 | LineChange line_change; |
| 890 | |
| 891 | /// Diffs for every file in form of |
| 892 | /// --- a/src/Storages/StorageReplicatedMergeTree.cpp |
| 893 | /// +++ b/src/Storages/StorageReplicatedMergeTree.cpp |
| 894 | /// @@ -1387,2 +1387 @@ bool StorageReplicatedMergeTree::tryExecuteMerge(const LogEntry & entry) |
| 895 | /// - table_lock, entry.create_time, reserved_space, entry.deduplicate, |
| 896 | /// - entry.force_ttl); |
| 897 | /// + table_lock, entry.create_time, reserved_space, entry.deduplicate); |
| 898 | |
| 899 | size_t diff_size = 0; |
| 900 | while (!in.eof()) |
| 901 | { |
| 902 | if (checkString("@@ ", in)) |
| 903 | { |
| 904 | if (!file_change_and_line_changes) |
| 905 | { |
| 906 | auto file_name = new_file_path.empty() ? old_file_path : new_file_path; |
| 907 | auto it = file_changes.find(file_name); |
| 908 | if (file_changes.end() != it) |
| 909 | file_change_and_line_changes = &it->second; |
| 910 | } |
| 911 | |
| 912 | if (file_change_and_line_changes) |
| 913 | { |
| 914 | uint32_t old_lines = 1; |
| 915 | uint32_t new_lines = 1; |
| 916 | |
| 917 | assertChar('-', in); |
| 918 | readText(line_change.hunk_start_line_number_old, in); |
| 919 | if (checkChar(',', in)) |
| 920 | readText(old_lines, in); |
| 921 | |
| 922 | assertString(" +", in); |
| 923 | readText(line_change.hunk_start_line_number_new, in); |
| 924 | if (checkChar(',', in)) |
| 925 | readText(new_lines, in); |
| 926 | |
| 927 | /// This is needed to simplify the logic of updating snapshot: |
| 928 | /// When all lines are removed we can treat it as repeated removal of line with number 1. |
| 929 | if (line_change.hunk_start_line_number_new == 0) |
| 930 | line_change.hunk_start_line_number_new = 1; |
| 931 | |
| 932 | assertString(" @@", in); |
| 933 | if (checkChar(' ', in)) |
| 934 | readStringUntilNextLine(line_change.hunk_context, in); |
| 935 | else |
| 936 | assertChar('\n', in); |
| 937 |
no test coverage detected