Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jul 2017 19:53:02 -0700
From:      Conrad Meyer <cem@freebsd.org>
To:        "Pedro F. Giffuni" <pfg@freebsd.org>
Cc:        src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r320579 - head/usr.bin/patch
Message-ID:  <CAG6CVpW4DYOzyacfEVQq%2B1WBGd1KO0m79zqJbGYPAyb6zS_5TQ@mail.gmail.com>
In-Reply-To: <201707022100.v62L0Ume001253@repo.freebsd.org>
References:  <201707022100.v62L0Ume001253@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Pedro,

Does this change the behavior of 'patch -p1' (for example) with 'git
diff' generated diffs?  So patches that could be applied with -p1
before now need to be applied with -p0?  Or is this a different mode
of patch?

If so, that's a somewhat surprising change in behavior.  Does GNU
patch have the same behavior?

Thanks,
Conrad

On Sun, Jul 2, 2017 at 2:00 PM, Pedro F. Giffuni <pfg@freebsd.org> wrote:
> Author: pfg
> Date: Sun Jul  2 21:00:30 2017
> New Revision: 320579
> URL: https://svnweb.freebsd.org/changeset/base/320579
>
> Log:
>   patch(1): add support for git generated diffs.
>
>   Sometimes patches coming from other places have extra a/ and b/
>   directories prepended to filenames.
>
>   Obtained from:        OpenBSD (CVS rev. 1.57, 1.58)
>
> Modified:
>   head/usr.bin/patch/pch.c
>
> Modified: head/usr.bin/patch/pch.c
> ==============================================================================
> --- head/usr.bin/patch/pch.c    Sun Jul  2 20:47:25 2017        (r320578)
> +++ head/usr.bin/patch/pch.c    Sun Jul  2 21:00:30 2017        (r320579)
> @@ -264,6 +264,7 @@ intuit_diff_type(void)
>         char    *s, *t;
>         int     indent, retval;
>         struct file_name names[MAX_FILE];
> +       int     piece_of_git = 0;
>
>         memset(names, 0, sizeof(names));
>         ok_to_create_file = false;
> @@ -308,14 +309,20 @@ intuit_diff_type(void)
>                 if (!stars_last_line && strnEQ(s, "*** ", 4))
>                         names[OLD_FILE].path = fetchname(s + 4,
>                             &names[OLD_FILE].exists, strippath);
> -               else if (strnEQ(s, "--- ", 4))
> -                       names[NEW_FILE].path = fetchname(s + 4,
> +               else if (strnEQ(s, "--- ", 4)) {
> +                       size_t off = 4;
> +                       if (piece_of_git && strippath == 957)
> +                               off = 6;
> +                       names[NEW_FILE].path = fetchname(s + off,
>                             &names[NEW_FILE].exists, strippath);
> -               else if (strnEQ(s, "+++ ", 4))
> +               } else if (strnEQ(s, "+++ ", 4)) {
>                         /* pretend it is the old name */
> -                       names[OLD_FILE].path = fetchname(s + 4,
> +                       size_t off = 4;
> +                       if (piece_of_git && strippath == 957)
> +                               off = 6;
> +                       names[OLD_FILE].path = fetchname(s + off,
>                             &names[OLD_FILE].exists, strippath);
> -               else if (strnEQ(s, "Index:", 6))
> +               } else if (strnEQ(s, "Index:", 6))
>                         names[INDEX_FILE].path = fetchname(s + 6,
>                             &names[INDEX_FILE].exists, strippath);
>                 else if (strnEQ(s, "Prereq:", 7)) {
> @@ -330,6 +337,9 @@ intuit_diff_type(void)
>                                 free(revision);
>                                 revision = NULL;
>                         }
> +               } else if (strnEQ(s, "diff --git a/", 13)) {
> +                       /* Git-style diffs. */
> +                       piece_of_git = 1;
>                 } else if (strnEQ(s, "==== ", 5)) {
>                         /* Perforce-style diffs. */
>                         if ((t = strstr(s + 5, " - ")) != NULL)
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpW4DYOzyacfEVQq%2B1WBGd1KO0m79zqJbGYPAyb6zS_5TQ>