Skip to content

git-p4.py: fix --prepare-p4-only error with multiple commits - #775

Closed
seraphire wants to merge 1 commit into
git:masterfrom
seraphire:seraphire/p4-hook
Closed

seraphire wants to merge 1 commit into
git:masterfrom
seraphire:seraphire/p4-hook

Conversation

@seraphire

Copy link
Copy Markdown
Contributor

When using git p4 submit with the --prepare-p4-only option, the program
should prepare a single p4 changelist and notify the user that more
commits are pending and then stop processing.

A bug has been introduced by the p4-changelist hook feature that
causes the program to continue to try and process all pending
changelists at the same time.

The function applyCommit should return True when applying the commit
was successful and the program should continue. In the case of the
--prepare-p4-only flag, the function should return False, alerting the
caller that the program should not proceed with additional commits.

Change the return value from True to False in the applyCommit function
when git-p4 is executed with --prepare-p4-only flag.

Thanks for taking the time to contribute to Git! Please be advised that the
Git community does not use github.com for their contributions. Instead, we use
a mailing list (git@vger.kernel.org) for code submissions, code reviews, and
bug reports. Nevertheless, you can use GitGitGadget (https://gitgitgadget.github.io/)
to conveniently send your Pull Requests commits to our mailing list.

Please read the "guidelines for contributing" linked above!

@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit 3ecbc700296e7bcb188ead5ad73a47d36f853501:
Commit not signed off

@seraphire
seraphire force-pushed the seraphire/p4-hook branch from 3ecbc70 to 57a34af Compare May 1, 2020 14:04
@seraphire

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

@gitgitgadget-git

Copy link
Copy Markdown

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Ben Keene via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Ben Keene <seraphire@gmail.com>
>
> When using git p4 submit with the --prepare-p4-only option, the program
> should prepare a single p4 changelist and notify the user that more
> commits are pending and then stop processing.
>
> A bug has been introduced by the p4-changelist hook feature that
> causes the program to continue to try and process all pending
> changelists at the same time.
>
> The function applyCommit should return True when applying the commit
> was successful and the program should continue. In the case of the
> --prepare-p4-only flag, the function should return False, alerting the
> caller that the program should not proceed with additional commits.
>
> Change the return value from True to False in the applyCommit function
> when git-p4 is executed with --prepare-p4-only flag.
>
> Signed-off-by: Ben Keene <seraphire@gmail.com>
> ---

I do not do P4, so asking those who touched the program in the past
year and half for opinions.

Thanks.

> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-775%2Fseraphire%2Fseraphire%2Fp4-hook-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-775/seraphire/seraphire/p4-hook-v1
> Pull-Request: https://github.com/git/git/pull/775
>
>  git-p4.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index b8b2a1679e7..d9ced1bf552 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1984,7 +1984,7 @@ def get_diff_description(self, editedFiles, filesToAdd, symlinks):
>          return (diff + newdiff).replace('\r\n', '\n')
>  
>      def applyCommit(self, id):
> -        """Apply one commit, return True if it succeeded."""
> +        """Apply one commit, return True if it should continue processing."""
>  
>          print("Applying", read_pipe(["git", "show", "-s",
>                                       "--format=format:%h %s", id]))
> @@ -2222,7 +2222,7 @@ def applyCommit(self, id):
>                          print("  " + f)
>                  print("")
>                  sys.stdout.flush()
> -                return True
> +                return False
>  
>              if self.edit_template(fileName):
>                  if not self.no_verify:
>
> base-commit: d61d20c9b413225793f8a0b491bbbec61c184e26

@gitgitgadget-git

Copy link
Copy Markdown

This branch is now known as bk-p4-prepare-p4-only-fix.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 3d57095.

@gitgitgadget-git gitgitgadget-git Bot added the pu label May 1, 2020
@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via f1a8421.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 090e0d4.

@gitgitgadget-git

Copy link
Copy Markdown

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Ben Keene via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Ben Keene <seraphire@gmail.com>
>
> When using git p4 submit with the --prepare-p4-only option, the program
> should prepare a single p4 changelist and notify the user that more
> commits are pending and then stop processing.
> ...

When merged to 'pu', this seems to break builds/tests at Travis CI.

Compare a good run with this topic deliberately ejected from 'pu':

    https://travis-ci.org/github/git/git/builds/683614214

and a bad one with this topic kept in 'pu':

    https://travis-ci.org/github/git/git/jobs/683604200

@seraphire

seraphire commented May 6, 2020 via email

Copy link
Copy Markdown
Contributor Author

@dscho

dscho commented May 6, 2020

Copy link
Copy Markdown
Member

|I'll look into it. Thanks for the heads up. | ||

As with previous PR comments: the Git mailing list does not see those. Please use the instructions in the "reply to this" link together with the link to the email you are responding to in order to reply to the original mail that only has been mirrored here.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 0239d78.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 31ff9f2.

When using git p4 submit with the --prepare-p4-only option, the program
should prepare a single p4 changelist and notify the user that more
commits are pending and then stop processing.

A bug has been introduced by the p4-changelist hook feature that
causes the program to continue to try and process all pending
changelists at the same time.

The function applyCommit returns True when applying the commit
was successful and the program should continue. However, when the
optional flag --prepare-p4-only is set, the program should stop
after the first application.

Change the logic in the run method for P4Submit to check for the
flag --prepare-p4-only after successfully completing the applyCommit
method.

Be aware - this change will fix the existing test error in t9807.23
for --prepare-p4-only. However there is insufficent coverage for
this flag.  If more than 1 commit is pending submission to P4, the
method will properly prepare the P4 changelist, however it will
still exit the application with an exitcode of 1.

The current documentation does not define what the exit code should be
in this condition.
(See: https://git-scm.com/docs/git-p4#Documentation/git-p4.txt---prepare-p4-only)

Signed-off-by: Ben Keene <seraphire@gmail.com>
@seraphire
seraphire force-pushed the seraphire/p4-hook branch from 57a34af to a554a65 Compare May 8, 2020 18:33
@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via cb6c702.

@gitgitgadget-git

Copy link
Copy Markdown

Found multiple candidates in gitster/git:
refs/remotes/gitster/bk-p4-prepare-p4-only-fix
refs/remotes/gitster/bk/p4-prepare-p4-only-fix;

Using the first one.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 6b41945.

@gitgitgadget-git

Copy link
Copy Markdown

Found multiple candidates in gitster/git:
refs/remotes/gitster/bk-p4-prepare-p4-only-fix
refs/remotes/gitster/bk/p4-prepare-p4-only-fix;

Using the first one.

@seraphire

Copy link
Copy Markdown
Contributor Author

I'm not sure how there are two branches, but the code I posted Saturday with commit a554a65 is the code that passes the tests. The previous submission is the one that does not pass the tests.

I see that I didn't /submit so I will do that now.

@seraphire

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

@gitgitgadget-git

Copy link
Copy Markdown

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Ben Keene via GitGitGadget" <gitgitgadget@gmail.com> writes:

> ...
> Be aware - this change will fix the existing test error in t9807.23
> for --prepare-p4-only. However there is insufficent coverage for
> this flag.  If more than 1 commit is pending submission to P4, the
> method will properly prepare the P4 changelist, however it will
> still exit the application with an exitcode of 1.
>
> The current documentation does not define what the exit code should be
> in this condition.
> (See: https://git-scm.com/docs/git-p4#Documentation/git-p4.txt---prepare-p4-only)

Then some proposal to define what the behaviour should be is needed,
the consensus implements and then documented.

>
> Signed-off-by: Ben Keene <seraphire@gmail.com>
> ---


>     git-p4.py: fix --prepare-p4-only error with multiple commits
>     
>     When using git p4 submit with the --prepare-p4-only option, the program
>     should prepare a single p4 changelist and notify the user that more
>     commits are pending and then stop processing.
>     
>     A bug has been introduced by the p4-changelist hook feature that causes
>     the program to continue to try and process all pending changelists at
>     the same time.
>     
>     The function applyCommit should return True when applying the commit was
>     successful and the program should continue. In the case of the
>     --prepare-p4-only flag, the function should return False, alerting the
>     caller that the program should not proceed with additional commits.
>     
>     Change the return value from True to False in the applyCommit function
>     when git-p4 is executed with --prepare-p4-only flag.

This space below the three-dash-line is the best place to describe
the difference between the previous version and this one.  It seems
that the above text is not such a "here are what was bad/missing in
v1 that got fixed/extended", or a copy of the log message (like many
patches that come from GGG has).  I am a bit puzzled what it is, but
for now let's pretend there wasn't any text below the three-dash-line
and read on.

>  git-p4.py | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index b8b2a1679e7..c4a4012bcc1 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -2537,11 +2537,12 @@ def run(self, args):
>                  ok = self.applyCommit(commit)
>              if ok:
>                  applied.append(commit)
> -            else:
> -                if self.prepare_p4_only and i < last:
> -                    print("Processing only the first commit due to option" \
> -                          " --prepare-p4-only")

So, it used to be that after failing to apply a commit, unless we
are at the last step, we gave a message and left the loop under the
prepare-p4-only mode.  We did not do anything special under the
prepare-p4-only mode if applyCommit returned a success.

> +                if self.prepare_p4_only:
> +                    if i < last:
> +                        print("Processing only the first commit due to option" \
> +                                " --prepare-p4-only")

Now, after successfully applying, we leave the loop under the
prepare-p4-only mode.  We give the message only when we are not at
the last step.

>                      break
> +            else:

So..., what happens when the first step fails to apply and then the
user tells us to skip the commit?  We'll go on to the next commit
and then applyCommit() may say 'ok' this time around.  Does that
count as "processed only the first commit and we are done"?

>                  if i < last:
>                      # prompt for what to do, or use the option/variable
>                      if self.conflict_behavior == "ask":
>
> base-commit: 07d8ea56f2ecb64b75b92264770c0a664231ce17

@gitgitgadget-git

Copy link
Copy Markdown

This branch is now known as bk/p4-prepare-p4-only-fix.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via a421d14.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via c13bd33.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 52148d8.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 0f026ca.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via c99e65b.

@gitgitgadget-git

Copy link
Copy Markdown

On the Git mailing list, Luke Diamand wrote (reply to this):

On Tue, 12 May 2020 at 21:05, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Ben Keene via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > ...
> > Be aware - this change will fix the existing test error in t9807.23
> > for --prepare-p4-only. However there is insufficent coverage for
> > this flag.  If more than 1 commit is pending submission to P4, the
> > method will properly prepare the P4 changelist, however it will
> > still exit the application with an exitcode of 1.
> >
> > The current documentation does not define what the exit code should be
> > in this condition.
> > (See: https://git-scm.com/docs/git-p4#Documentation/git-p4.txt---prepare-p4-only)
>
> Then some proposal to define what the behaviour should be is needed,
> the consensus implements and then documented.

It looks like it's always been slightly confusing (at least to me).

If prepare_p4_only is True, applyCommit() will only fail if the patch
could not be applied (which is what you would expect).

If that happens I would think it would make sense to bail out - I
would think most users will want to rebase and try again rather than
blithely carrying on.

The "i < last" logic in the original patch from 2012 seems to mean
that you only get the message "Processing only the first commit due to
option prepare-p4-only" if there is an error and you're not about to
drop out anyway.

I personally no longer use --prepare-p4-only, now that we have the
git-p4 shelve support. I would imagine this is true for a lot of
people.

The logic in Ben's change seems much more sensible.

Luke


>
> >
> > Signed-off-by: Ben Keene <seraphire@gmail.com>
> > ---
>
>
> >     git-p4.py: fix --prepare-p4-only error with multiple commits
> >
> >     When using git p4 submit with the --prepare-p4-only option, the program
> >     should prepare a single p4 changelist and notify the user that more
> >     commits are pending and then stop processing.
> >
> >     A bug has been introduced by the p4-changelist hook feature that causes
> >     the program to continue to try and process all pending changelists at
> >     the same time.
> >
> >     The function applyCommit should return True when applying the commit was
> >     successful and the program should continue. In the case of the
> >     --prepare-p4-only flag, the function should return False, alerting the
> >     caller that the program should not proceed with additional commits.
> >
> >     Change the return value from True to False in the applyCommit function
> >     when git-p4 is executed with --prepare-p4-only flag.
>
> This space below the three-dash-line is the best place to describe
> the difference between the previous version and this one.  It seems
> that the above text is not such a "here are what was bad/missing in
> v1 that got fixed/extended", or a copy of the log message (like many
> patches that come from GGG has).  I am a bit puzzled what it is, but
> for now let's pretend there wasn't any text below the three-dash-line
> and read on.
>
> >  git-p4.py | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/git-p4.py b/git-p4.py
> > index b8b2a1679e7..c4a4012bcc1 100755
> > --- a/git-p4.py
> > +++ b/git-p4.py
> > @@ -2537,11 +2537,12 @@ def run(self, args):
> >                  ok = self.applyCommit(commit)
> >              if ok:
> >                  applied.append(commit)
> > -            else:
> > -                if self.prepare_p4_only and i < last:
> > -                    print("Processing only the first commit due to option" \
> > -                          " --prepare-p4-only")
>
> So, it used to be that after failing to apply a commit, unless we
> are at the last step, we gave a message and left the loop under the
> prepare-p4-only mode.  We did not do anything special under the
> prepare-p4-only mode if applyCommit returned a success.
>
> > +                if self.prepare_p4_only:
> > +                    if i < last:
> > +                        print("Processing only the first commit due to option" \
> > +                                " --prepare-p4-only")
>
> Now, after successfully applying, we leave the loop under the
> prepare-p4-only mode.  We give the message only when we are not at
> the last step.
>
> >                      break
> > +            else:
>
> So..., what happens when the first step fails to apply and then the
> user tells us to skip the commit?  We'll go on to the next commit
> and then applyCommit() may say 'ok' this time around.  Does that
> count as "processed only the first commit and we are done"?
>
> >                  if i < last:
> >                      # prompt for what to do, or use the option/variable
> >                      if self.conflict_behavior == "ask":
> >
> > base-commit: 07d8ea56f2ecb64b75b92264770c0a664231ce17

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 07ea38e.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via bb69d07.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 558b2cb.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 39e168e.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 928f614.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 0eae031.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into next via c1b4644.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via ef3403d.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 51d2b95.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 6a83942.

@APACGAMONDE

Copy link
Copy Markdown

Thank you!

@APACGAMONDE

This comment has been minimized.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via abed529.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 1074caa.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via e5dec08.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into pu via 7a8fec9.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into next via 7a8fec9.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into master via 7a8fec9.

@gitgitgadget-git

Copy link
Copy Markdown

Closed via 7a8fec9.

@gitgitgadget-git gitgitgadget-git Bot closed this Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants