Skip to content

add -p: fix checkout -p with pathological context #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

phillipwood
Copy link

@phillipwood phillipwood commented Jun 11, 2019

When I fixed the hunk offsets in add -p when hunks are skipped I forgot that the reverse patch case needs to be handled differently.

Commit fecc6f3 ("add -p: adjust offsets of subsequent hunks when one is
skipped", 2018-03-01) fixed adding hunks in the correct place when a
previous hunk has been skipped. However it did not address patches that
are applied in reverse. In that case we need to adjust the pre-image
offset so that when apply reverses the patch the post-image offset is
adjusted correctly. We subtract rather than add the delta as the patch
is reversed (the easiest way to think about it is to consider a hunk of
deletions that is skipped - in that case we want to reduce offset so we
need to subtract).

Signed-off-by: Phillip Wood <[email protected]>
@gitgitgadget
Copy link

gitgitgadget bot commented Jun 11, 2019

Welcome to GitGitGadget

Hi @phillipwood, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that this Pull Request has a good description, as it will be used as cover letter.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "commit:", and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a PR comment of the form /allow <username>.

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions.

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox ("raw") file corresponding to the mail you want to reply to from the Git mailing list. If you use GMail, you can upload that raw mbox file via:

curl -g --user "<EMailAddress>:<Password>" --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

phillipwood referenced this pull request in git-for-windows/git Jun 11, 2019
The Perl script backing `git add -p` is used not only for that command,
but also for `git stash -p`, `git reset -p` and `git checkout -p`.

In preparation for teaching the C version of `git add -p` to support
also the latter commands, let's abstract away what is "stage" specific
into a dedicated data structure describing the differences between the
patch modes.

As we prepare for calling the built-in `git add -p` in
`run_add_interactive()` via code paths that have not let `add_config()`
do its work, we have to make sure to re-parse the config using that
function in those cases.

Finally, please note that the Perl version tries to make sure that the
diffs are only generated for the modified files. This is not actually
necessary, as the calls to Git's diff machinery already perform that
work, and perform it well. This makes it unnecessary to port the
`FILTER` field of the `%patch_modes` struct, as well as the
`get_diff_reference()` function.

Signed-off-by: Johannes Schindelin <[email protected]>
@dscho
Copy link
Member

dscho commented Jun 11, 2019

/allow phillipwood

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 11, 2019

User phillipwood is now allowed to use GitGitGadget.

@dscho
Copy link
Member

dscho commented Jun 11, 2019

@phillipwood please note that the PR description (i.e. the title plus the first comment) will be used as cover letter... you might want to edit the first comment.

@phillipwood
Copy link
Author

Thanks @dscho, I'll edit the first comment. Thanks for all your efforts on the CI as well - it's great to be able to run tests on windows before posting to the list.

@phillipwood
Copy link
Author

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 12, 2019

Submitted as [email protected]

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 13, 2019

This branch is now known as pw/add-p-recount.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 13, 2019

This patch series was integrated into pu via git@5b124ad.

@gitgitgadget gitgitgadget bot added the pu label Jun 13, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Jun 13, 2019

This patch series was integrated into pu via git@7426721.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 14, 2019

This patch series was integrated into pu via git@c32558c.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 18, 2019

This patch series was integrated into pu via git@33b8138.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 21, 2019

This patch series was integrated into pu via git@172874c.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 24, 2019

This patch series was integrated into pu via git@0648743.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 26, 2019

This patch series was integrated into pu via git@3fe6252.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 26, 2019

This patch series was integrated into next via git@63e063d.

@gitgitgadget gitgitgadget bot added the next label Jun 26, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Jun 28, 2019

This patch series was integrated into pu via git@cb45d0a.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 28, 2019

This patch series was integrated into pu via git@f26fc54.

@gitgitgadget
Copy link

gitgitgadget bot commented Jun 28, 2019

This patch series was integrated into pu via git@d2367d8.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 1, 2019

This patch series was integrated into pu via git@9009ffa.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 2, 2019

This patch series was integrated into pu via git@af0c776.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 3, 2019

This patch series was integrated into pu via git@e58fb3b.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 3, 2019

This patch series was integrated into pu via git@a97d1f9.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 9, 2019

This patch series was integrated into pu via git@12bd157.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 10, 2019

This patch series was integrated into pu via git@1b074e1.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 10, 2019

This patch series was integrated into next via git@1b074e1.

@gitgitgadget
Copy link

gitgitgadget bot commented Jul 10, 2019

This patch series was integrated into master via git@1b074e1.

@gitgitgadget gitgitgadget bot added the master label Jul 10, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Jul 10, 2019

Closed via 1b074e1.

@gitgitgadget gitgitgadget bot closed this Jul 10, 2019
@phillipwood phillipwood deleted the wip/fix-checkout-p branch August 12, 2021 13:35
@phillipwood phillipwood restored the wip/fix-checkout-p branch August 15, 2021 15:21
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.

2 participants