MCPcopy Create free account
hub / github.com/git/git / match_fragment

Function match_fragment

apply.c:2597–2813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2595}
2596
2597static int match_fragment(struct apply_state *state,
2598 struct image *img,
2599 struct image *preimage,
2600 struct image *postimage,
2601 unsigned long current,
2602 int current_lno,
2603 unsigned ws_rule,
2604 int match_beginning, int match_end)
2605{
2606 int i;
2607 const char *orig, *target;
2608 struct strbuf fixed = STRBUF_INIT;
2609 char *fixed_buf;
2610 size_t fixed_len;
2611 int preimage_limit;
2612 int ret;
2613
2614 if (preimage->line_nr + current_lno <= img->line_nr) {
2615 /*
2616 * The hunk falls within the boundaries of img.
2617 */
2618 preimage_limit = preimage->line_nr;
2619 if (match_end && (preimage->line_nr + current_lno != img->line_nr)) {
2620 ret = 0;
2621 goto out;
2622 }
2623 } else if (state->ws_error_action == correct_ws_error &&
2624 (ws_rule & WS_BLANK_AT_EOF)) {
2625 /*
2626 * This hunk extends beyond the end of img, and we are
2627 * removing blank lines at the end of the file. This
2628 * many lines from the beginning of the preimage must
2629 * match with img, and the remainder of the preimage
2630 * must be blank.
2631 */
2632 preimage_limit = img->line_nr - current_lno;
2633 } else {
2634 /*
2635 * The hunk extends beyond the end of the img and
2636 * we are not removing blanks at the end, so we
2637 * should reject the hunk at this position.
2638 */
2639 ret = 0;
2640 goto out;
2641 }
2642
2643 if (match_beginning && current_lno) {
2644 ret = 0;
2645 goto out;
2646 }
2647
2648 /* Quick hash check */
2649 for (i = 0; i < preimage_limit; i++) {
2650 if ((img->line[current_lno + i].flag & LINE_PATCHED) ||
2651 (preimage->line[i].hash != img->line[current_lno + i].hash)) {
2652 ret = 0;
2653 goto out;
2654 }

Callers 1

find_posFunction · 0.85

Calls 7

line_by_line_fuzzy_matchFunction · 0.85
strbuf_growFunction · 0.85
ws_fix_copyFunction · 0.85
strbuf_initFunction · 0.85
strbuf_releaseFunction · 0.85
strbuf_detachFunction · 0.85
update_pre_post_imagesFunction · 0.85

Tested by

no test coverage detected