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

Jun Wu quark at fb.com
Mon Apr 24 16:29:16 EDT 2017


This fixes a 4-year bug. I think it is worth being merged.

Excerpts from Phil Cohen's message of 2017-04-24 13:10:00 -0700:
> [...]
>  
> @@ -97,8 +99,18 @@
>              x = PyFile_GetLine(fp, 0);
>              s = PyBytes_AsString(x);
>              c = *s;
> -            if (strcmp(s, "\\ No newline at end of file\n") == 0) {
> -                _fix_newline(hunk, a, b);
> +            char *prefix = "\\ No newline at end of file";
> +
> +            if (strncmp(s, prefix, strlen(prefix)) == 0) {
> +                bool canstripcr = true;
> +                size_t len = strlen(s);
> +                /* The "\\ No newline" line must end in CRLF to
> +                strip CRs -- see comment in diffhelpers.py */
> +                if (len > 2 && s[len - 2] != '\r') {
> +                    canstripcr = false;
> +                }
> +
> +                _fix_newline(hunk, a, b, canstripcr);
>                  continue;
>              }

Ideally this chunk belongs to the second patch, and the first patch has a
one line diff here replacing "_fix_newline(hunk, a, b)" with
"_fix_newline(hunk, a, b, 1)". Since the final state is the same, I wouldn't
be too nitpicking on this.

> [...]


More information about the Mercurial-devel mailing list