tbo...@web.de writes:

> @@ -1712,11 +1726,15 @@ static int parse_fragment(struct apply_state *state,
>                       if (!deleted && !added)
>                               leading++;
>                       trailing++;
> +                     if (!state->apply_in_reverse)
> +                             check_old_for_crlf(patch, line, len);
>                       if (!state->apply_in_reverse &&
>                           state->ws_error_action == correct_ws_error)
>                               check_whitespace(state, line, len, 
> patch->ws_rule);
>                       break;

This one is wrong.  You are looking at " " (common context) and you
should unconditionally call check_old for them.


>               case '-':
> +                     if (!state->apply_in_reverse)
> +                             check_old_for_crlf(patch, line, len);

This is correct.

There is "case '+':" below here you did not touch.  There should be

                case '+':
        +               if (state->apply_in_reverse)
        +                       check_old_for_crlf(...);

there.  Note that we call check_old() only when applying in reverse.

> @@ -2268,8 +2286,11 @@ static void show_stats(struct apply_state *state, 
> struct patch *patch)
>               add, pluses, del, minuses);
>  }
>  
> -static int read_old_data(struct stat *st, const char *path, struct strbuf 
> *buf)
> +static int read_old_data(struct stat *st, struct patch *patch,
> +                      const char *path, struct strbuf *buf)

The order of argument to have the patch structure earlier is
different from my version; what we see here looks much better to me.

>  {
> +     enum safe_crlf safe_crlf = patch->crlf_in_old ?
> +             SAFE_CRLF_KEEP_CRLF : SAFE_CRLF_RENORMALIZE;
>       switch (st->st_mode & S_IFMT) {
>       case S_IFLNK:
>               if (strbuf_readlink(buf, path, st->st_size) < 0)
> @@ -2278,7 +2299,15 @@ static int read_old_data(struct stat *st, const char 
> *path, struct strbuf *buf)
>       case S_IFREG:
>               if (strbuf_read_file(buf, path, st->st_size) != st->st_size)
>                       return error(_("unable to open or read %s"), path);
> -             convert_to_git(&the_index, path, buf->buf, buf->len, buf, 0);
> +            /*
> +             * "git apply" without "--index/--cached" should never look
> +             * at the index; the target file may not have been added to
> +             * the index yet, and we may not even be in any Git repository.
> +             * Pass NULL to convert_to_git() to stress this; the function
> +             * should never look at the index when explicit crlf option
> +             * is given.
> +             */
> +             convert_to_git(NULL, path, buf->buf, buf->len, buf, safe_crlf);

This comment is somewhat strangly indented.  I thought opening "/*"
alighs with the usual tab stop.

Thanks.

Reply via email to