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

Function find_pos

apply.c:2815–2901  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2813}
2814
2815static int find_pos(struct apply_state *state,
2816 struct image *img,
2817 struct image *preimage,
2818 struct image *postimage,
2819 int line,
2820 unsigned ws_rule,
2821 int match_beginning, int match_end)
2822{
2823 int i;
2824 unsigned long backwards, forwards, current;
2825 int backwards_lno, forwards_lno, current_lno;
2826
2827 /*
2828 * When running with --allow-overlap, it is possible that a hunk is
2829 * seen that pretends to start at the beginning (but no longer does),
2830 * and that *still* needs to match the end. So trust `match_end` more
2831 * than `match_beginning`.
2832 */
2833 if (state->allow_overlap && match_beginning && match_end &&
2834 img->line_nr - preimage->line_nr != 0)
2835 match_beginning = 0;
2836
2837 /*
2838 * If match_beginning or match_end is specified, there is no
2839 * point starting from a wrong line that will never match and
2840 * wander around and wait for a match at the specified end.
2841 */
2842 if (match_beginning)
2843 line = 0;
2844 else if (match_end)
2845 line = img->line_nr - preimage->line_nr;
2846
2847 /*
2848 * Because the comparison is unsigned, the following test
2849 * will also take care of a negative line number that can
2850 * result when match_end and preimage is larger than the target.
2851 */
2852 if ((size_t) line > img->line_nr)
2853 line = img->line_nr;
2854
2855 current = 0;
2856 for (i = 0; i < line; i++)
2857 current += img->line[i].len;
2858
2859 /*
2860 * There's probably some smart way to do this, but I'll leave
2861 * that to the smart and beautiful people. I'm simple and stupid.
2862 */
2863 backwards = current;
2864 backwards_lno = line;
2865 forwards = current;
2866 forwards_lno = line;
2867 current_lno = line;
2868
2869 for (i = 0; ; i++) {
2870 if (match_fragment(state, img, preimage, postimage,
2871 current, current_lno, ws_rule,
2872 match_beginning, match_end))

Callers 1

apply_one_fragmentFunction · 0.85

Calls 1

match_fragmentFunction · 0.85

Tested by

no test coverage detected