Re: [PATCH v3 1/2] merge-file: let conflict markers match end-of-line style of the context
- From
Torsten Bögershausen <tboegi@web.de>
- Date
- Jan 25, 2016, 08:32 UTC
- Message-ID
- <56A5DDA8.1030404@web.de>
- In-Reply-To
- <26c973eb3414a8634d515f3621c0ded77cf030ed.1453709205.git.johannes.schindelin@gmx.de>
On 25.01.16 09:07, Johannes Schindelin wrote: []
Show 14 quoted lines
> diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c > index 625198e..c852acc 100644 > --- a/xdiff/xmerge.c > +++ b/xdiff/xmerge.c > @@ -143,6 +143,35 @@ static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest) > return xdl_recs_copy_0(1, xe, i, count, add_nl, dest); > } > > +/* > + * Returns 1 if the i'th line ends in CR/LF (if it is the last line and > + * has no eol, the preceding line, if any), 0 if it ends in LF-only, and > + * -1 if the line ending cannot be determined. > + */ > +static int is_eol_crlf(xdfile_t *file, int i)
Minot nit: Could that be is_eol_crlf(xdfile_t *file, int lineno) (or may be) is_eol_crlf(const xdfile_t *file, int lineno) (or may be) has_eol_crlf(const xdfile_t *file, int lineno)
Show 23 quoted lines
> +{
> + long size;
> +
> + if (i < file->nrec - 1)
> + /* All lines before the last *must* end in LF */
> + return (size = file->recs[i]->size) > 1 &&
> + file->recs[i]->ptr[size - 2] == '\r';
> + if (!file->nrec)
> + /* Cannot determine eol style from empty file */
> + return -1;
> + if ((size = file->recs[i]->size) &&
> + file->recs[i]->ptr[size - 1] == '\n')
> + /* Last line; ends in LF; Is it CR/LF? */
> + return size > 1 &&
> + file->recs[i]->ptr[size - 2] == '\r';
> + if (!i)
> + /* The only line has no eol */
> + return -1;
> + /* Determine eol from second-to-last line */
> + return (size = file->recs[i - 1]->size) > 1 &&
> + file->recs[i - 1]->ptr[size - 2] == '\r';
> +}
> +