| 155 | } |
| 156 | |
| 157 | static bool changes_header_path(changes_slice_t line, changes_slice_t *path) { |
| 158 | static const char prefix[] = "diff --git a/"; |
| 159 | const size_t prefix_length = sizeof(prefix) - 1; |
| 160 | if (!changes_starts(line, prefix)) { |
| 161 | return false; |
| 162 | } |
| 163 | size_t rest = line.length - prefix_length; |
| 164 | if (rest < 5 || (rest - 3) % 2) { |
| 165 | return false; |
| 166 | } |
| 167 | size_t length = (rest - 3) / 2; |
| 168 | const unsigned char *first = line.bytes + prefix_length; |
| 169 | if (memcmp(first + length, " b/", 3) || memcmp(first, first + length + 3, length) || |
| 170 | !changes_path_valid(first, length)) { |
| 171 | return false; |
| 172 | } |
| 173 | for (size_t i = 0; i < length; i++) { |
| 174 | /* Git quotes these bytes even with core.quotePath=false. The existing |
| 175 | * reader does not decode that representation. Non-UTF8 remains raw. */ |
| 176 | if (first[i] < 32 || first[i] == 127 || first[i] == '"' || first[i] == '\\') { |
| 177 | return false; |
| 178 | } |
| 179 | } |
| 180 | *path = (changes_slice_t){first, length}; |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | static bool changes_mode(changes_slice_t line, const char *prefix) { |
| 185 | size_t length = strlen(prefix); |
no test coverage detected