[PATCH 1 of 2 STABLE] diffhelpers: add canstripcr=True to fix_newline

Augie Fackler raf at durin42.com
Tue Apr 25 11:55:54 EDT 2017


On Tue, Apr 25, 2017 at 10:56:13PM +0900, Yuya Nishihara wrote:
> On Mon, 24 Apr 2017 13:10:00 -0700, Phil Cohen wrote:
> > # HG changeset patch
> > # User Phil Cohen <phillco at fb.com>
> > # Date 1493055298 25200
> > #      Mon Apr 24 10:34:58 2017 -0700
> > # Branch stable
> > # Node ID 7f413064263ff1b3cf98d1b23ae35e4c098da482
> > # Parent  0537d2d94c0fb747e75272f9f950cc29b6e0dce8
> > diffhelpers: add canstripcr=True to fix_newline
>
> > When processing a patch ending in "\ No newline at end of file", we used to
> > remove the \n from the end of that line, and if a \r was present before the \n,
> > we would remove that as well, probably assuming the patch was from a Windows
> > system.
> >
> > However, this isn't always correct: patches created on Unix can legitimately end
> > in a CR, and so this logic will falsely strip the CR and fail to import.
> >
> > A better way to determine if the CR is part of the patch, or part of the newline
> > inserted by the patcher, is to see what the "\ No newline" line itself ends
> > with. If CRLF, then CRLFs may be stripped; if only LF, then only LFs may be.
>
> The idea sounds good.
>
> > @@ -54,9 +55,10 @@
> >  fix_newline(PyObject *self, PyObject *args)
> >  {
> >     PyObject *hunk, *a, *b;
> > -	if (!PyArg_ParseTuple(args, "OOO", &hunk, &a, &b))
> > +	bool canstripcr = true;
> > +	if (!PyArg_ParseTuple(args, "OOO|B", &hunk, &a, &b, &canstripcr))
> >             return NULL;
> > -	_fix_newline(hunk, a, b);
> > +	_fix_newline(hunk, a, b, canstripcr);
> >     return Py_BuildValue("l", 0);
> >  }
>
> This will break C API compatibility: new build of diffhelpers.so with old
> Mercurial. In general, we do rename the C function, but it wouldn't help
> since there's no try-catch around the call site of fix_newline().
>
> Maybe we could work around that by:
>
>  1. copy pure.diffhelpers.fix_newline() to patch.py (because pure module
>     can't be imported by name), and use the copy in Python code.
>  2. update all fix_newline() functions, except for the C function signature.

+1


More information about the Mercurial-devel mailing list