git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jerry Zhang <jerry@skydio.com>,
	Git Mailing List <git@vger.kernel.org>,
	ross@skydio.com, Abraham Bachrach <abe@skydio.com>,
	brian.kubisiak@skydio.com
Subject: Re: [PATCH v5] git-apply: allow simultaneous --cached and --3way options
Date: Mon, 12 Apr 2021 08:45:31 -0700	[thread overview]
Message-ID: <CABPp-BEmZrK9ambLHL=ryjRM22zqGn6vzc+2aGoy=x-Z3mwUdQ@mail.gmail.com> (raw)
In-Reply-To: <xmqqh7kgvr3i.fsf@gitster.g>

On Thu, Apr 8, 2021 at 6:33 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Jerry Zhang <jerry@skydio.com> writes:
>
> >  Documentation/git-apply.txt |  6 +++--
> >  apply.c                     |  9 ++++---
> >  t/t4108-apply-threeway.sh   | 50 +++++++++++++++++++++++++++++++++++++
> >  3 files changed, 59 insertions(+), 6 deletions(-)
>
> Nicely done.  Will queue.
>
> Elijah, how does this round look to you?

Sorry for the delay; modulo two minor issues with the commit message
it looks good to me.

This change won't allow git-apply to handle upstream renames, and
makes me wonder if we should lift the fall_back_threeway() logic out
of builtin/am.c and use it here.  This change also makes me wonder if
we should change git-am's --3way flag to make it not be treated as a
fallback to be consistent with what we are doing here.  But neither of
those changes need to be part of this patch.

> > diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
> > index 9144575299c264dd299b542b7b5948eef35f211c..aa1ae56a25e0428cabcfa2539900ef2a09abcb7c 100644
> > --- a/Documentation/git-apply.txt
> > +++ b/Documentation/git-apply.txt
> > @@ -87,8 +87,10 @@ OPTIONS
> >       Attempt 3-way merge if the patch records the identity of blobs it is supposed
> >       to apply to and we have those blobs available locally, possibly leaving the
> >       conflict markers in the files in the working tree for the user to
> > -     resolve.  This option implies the `--index` option, and is incompatible
> > -     with the `--reject` and the `--cached` options.
> > +     resolve.  This option implies the `--index` option unless the
> > +     `--cached` option is used, and is incompatible with the `--reject` option.
> > +     When used with the `--cached` option, any conflicts are left at higher stages
> > +     in the cache.
> >
> >  --build-fake-ancestor=<file>::
> >       Newer 'git diff' output has embedded 'index information'
> > diff --git a/apply.c b/apply.c
> > index 9bd4efcbced842d2c5c030a0f2178ddb36114600..dadab80ec967357b031657d4e3d0ae52fac11411 100644
> > --- a/apply.c
> > +++ b/apply.c
> > @@ -133,8 +133,6 @@ int check_apply_state(struct apply_state *state, int force_apply)
> >
> >       if (state->apply_with_reject && state->threeway)
> >               return error(_("--reject and --3way cannot be used together."));
> > -     if (state->cached && state->threeway)
> > -             return error(_("--cached and --3way cannot be used together."));
> >       if (state->threeway) {
> >               if (is_not_gitdir)
> >                       return error(_("--3way outside a repository"));
> > @@ -4644,8 +4642,11 @@ static int write_out_results(struct apply_state *state, struct patch *list)
> >                               fprintf(stderr, "U %s\n", item->string);
> >               }
> >               string_list_clear(&cpath, 0);
> > -
> > -             repo_rerere(state->repo, 0);
> > +             /* Rerere relies on the partially merged result being in the working tree
> > +              * with conflict markers, but that isn't written with --cached.
> > +              */
> > +             if (!state->cached)
> > +                     repo_rerere(state->repo, 0);
> >       }
> >
> >       return errs;
> > diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh
> > index 9ff313f976422f9c12dc8032d14567b54cfe3765..65147efdea9a00e30d156e6f4d5d72a3987f230d 100755
> > --- a/t/t4108-apply-threeway.sh
> > +++ b/t/t4108-apply-threeway.sh
> > @@ -180,4 +180,54 @@ test_expect_success 'apply -3 with ambiguous repeating file' '
> >       test_cmp expect one_two_repeat
> >  '
> >
> > +test_expect_success 'apply with --3way --cached clean apply' '
> > +     # Merging side should be similar to applying this patch
> > +     git diff ...side >P.diff &&
> > +
> > +     # The corresponding cleanly applied merge
> > +     git reset --hard &&
> > +     git checkout main~ &&
> > +     git merge --no-commit side &&
> > +     git ls-files -s >expect.ls &&
> > +
> > +     # should succeed
> > +     git reset --hard &&
> > +     git checkout main~ &&
> > +     git apply --cached --3way P.diff &&
> > +     git ls-files -s >actual.ls &&
> > +     print_sanitized_conflicted_diff >actual.diff &&
> > +
> > +     # The cache should resemble the corresponding merge
> > +     # (both files at stage #0)
> > +     test_cmp expect.ls actual.ls &&
> > +     # However the working directory should not change
> > +     >expect.diff &&
> > +     test_cmp expect.diff actual.diff
> > +'
> > +
> > +test_expect_success 'apply with --3way --cached and conflicts' '
> > +     # Merging side should be similar to applying this patch
> > +     git diff ...side >P.diff &&
> > +
> > +     # The corresponding conflicted merge
> > +     git reset --hard &&
> > +     git checkout main^0 &&
> > +     test_must_fail git merge --no-commit side &&
> > +     git ls-files -s >expect.ls &&
> > +
> > +     # should fail to apply
> > +     git reset --hard &&
> > +     git checkout main^0 &&
> > +     test_must_fail git apply --cached --3way P.diff &&
> > +     git ls-files -s >actual.ls &&
> > +     print_sanitized_conflicted_diff >actual.diff &&
> > +
> > +     # The cache should resemble the corresponding merge
> > +     # (one file at stage #0, one file at stages #1 #2 #3)
> > +     test_cmp expect.ls actual.ls &&
> > +     # However the working directory should not change
> > +     >expect.diff &&
> > +     test_cmp expect.diff actual.diff
> > +'
> > +
> >  test_done

  reply	other threads:[~2021-04-12 15:45 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-03  1:34 [PATCH 0/1] git-apply: Allow " Jerry Zhang
2021-04-03  1:34 ` [PATCH 1/1] " Jerry Zhang
2021-04-03  3:46   ` Elijah Newren
2021-04-03  4:26     ` Junio C Hamano
2021-04-04  1:02       ` Junio C Hamano
2021-04-05 22:12         ` Jerry Zhang
2021-04-05 22:23           ` Junio C Hamano
2021-04-05 23:29             ` Jerry Zhang
2021-04-06  0:10               ` Junio C Hamano
2021-04-05 22:08     ` Jerry Zhang
2021-04-05 22:19   ` [PATCH V2] " Jerry Zhang
2021-04-05 22:46     ` Junio C Hamano
2021-04-06  2:52       ` Jerry Zhang
2021-04-06  5:52         ` Junio C Hamano
2021-04-06 21:56           ` Jerry Zhang
2021-04-07  2:25             ` Jerry Zhang
2021-04-06  2:49     ` [PATCH v3] git-apply: allow " Jerry Zhang
2021-04-07 18:03       ` [PATCH v4] " Jerry Zhang
2021-04-07 19:00         ` Junio C Hamano
2021-04-08  2:13         ` [PATCH v5] " Jerry Zhang
2021-04-08 13:33           ` Junio C Hamano
2021-04-12 15:45             ` Elijah Newren [this message]
2021-04-12 18:26               ` Junio C Hamano
2021-04-12 15:40           ` Elijah Newren
2021-04-12 18:27             ` Junio C Hamano
2021-04-03  3:04 ` [PATCH 0/1] git-apply: Allow " Elijah Newren
2021-04-05 22:05   ` Jerry Zhang
2021-04-03  5:24 ` Bagas Sanjaya
     [not found]   ` <CAMKO5CtiW84E4XjnPRf-yOPp+ua_u07LsAu=BB0YhmP3+3kYiw@mail.gmail.com>
2021-04-03  8:05     ` Bagas Sanjaya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABPp-BEmZrK9ambLHL=ryjRM22zqGn6vzc+2aGoy=x-Z3mwUdQ@mail.gmail.com' \
    --to=newren@gmail.com \
    --cc=abe@skydio.com \
    --cc=brian.kubisiak@skydio.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jerry@skydio.com \
    --cc=ross@skydio.com \
    --subject='Re: [PATCH v5] git-apply: allow simultaneous --cached and --3way options' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).