* "buf" has the file contents to be patched (read from various sources). * attach it to "image" and add line-based index to it. * "image" now owns the "buf". */
| 328 | * "image" now owns the "buf". |
| 329 | */ |
| 330 | static void image_prepare(struct image *image, char *buf, size_t len, |
| 331 | int prepare_linetable) |
| 332 | { |
| 333 | const char *cp, *ep; |
| 334 | |
| 335 | image_clear(image); |
| 336 | strbuf_attach(&image->buf, buf, len, len + 1); |
| 337 | |
| 338 | if (!prepare_linetable) |
| 339 | return; |
| 340 | |
| 341 | ep = image->buf.buf + image->buf.len; |
| 342 | cp = image->buf.buf; |
| 343 | while (cp < ep) { |
| 344 | const char *next; |
| 345 | for (next = cp; next < ep && *next != '\n'; next++) |
| 346 | ; |
| 347 | if (next < ep) |
| 348 | next++; |
| 349 | image_add_line(image, cp, next - cp, 0); |
| 350 | cp = next; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | static void image_remove_first_line(struct image *img) |
| 355 | { |
no test coverage detected