The path of "diff --git a/P b/P". Without renames both sides name the same * file, so the line is the path twice; that also reads a path with " b/" in * it. NULL for anything else: git quotes a path with a quote, a backslash or * a control character in it, and that form is not read. */
| 122 | * it. NULL for anything else: git quotes a path with a quote, a backslash or |
| 123 | * a control character in it, and that form is not read. */ |
| 124 | static const char *df_header_path(cbm_diff_t *d, const df_line_t *line) { |
| 125 | static const char open[] = "diff --git a/"; |
| 126 | static const char mid[] = " b/"; |
| 127 | size_t open_len = sizeof(open) - 1; |
| 128 | size_t mid_len = sizeof(mid) - 1; |
| 129 | if (!df_starts(line, open)) { |
| 130 | return NULL; |
| 131 | } |
| 132 | size_t rest = line->len - open_len; |
| 133 | if (rest < mid_len + 2 || (rest - mid_len) % 2 != 0) { |
| 134 | return NULL; |
| 135 | } |
| 136 | size_t path_len = (rest - mid_len) / 2; |
| 137 | const char *left = line->text + open_len; |
| 138 | const char *right = left + path_len + mid_len; |
| 139 | if (memcmp(left + path_len, mid, mid_len) != 0 || memcmp(left, right, path_len) != 0) { |
| 140 | return NULL; |
| 141 | } |
| 142 | return cbm_arena_strndup(&d->arena, left, path_len); |
| 143 | } |
| 144 | |
| 145 | static cbm_diff_file_t *df_add_file(cbm_diff_t *d, const char *path) { |
| 146 | if (d->file_count == d->file_cap) { |
no test coverage detected