{"thread":{"id":"51294","subject":"[PATCH 0/1] add -p: fix checkout -p with pathological context","startedAt":"2019-06-12T09:25:30Z","lastAt":"2019-06-12T09:25:31Z","messageCount":2,"participants":["Phillip Wood via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"377053","messageId":"pull.262.git.gitgitgadget@gmail.com","threadId":"51294","inReplyTo":null,"subject":"[PATCH 0/1] add -p: fix checkout -p with pathological context","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-06-12T09:25:27Z","receivedAt":"2019-06-12T09:25:30Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"When I fixed the hunk offsets in add -p when hunks are skipped I forgot that\nthe reverse patch case needs to be handled differently.\n\nPhillip Wood (1):\n  add -p: fix checkout -p with pathological context\n\n git-add--interactive.perl  | 6 +++++-\n t/t3701-add-interactive.sh | 8 ++++++++\n 2 files changed, 13 insertions(+), 1 deletion(-)\n\n\nbase-commit: aeb582a98374c094361cba1bd756dc6307432c42\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-262%2Fphillipwood%2Fwip%2Ffix-checkout-p-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-262/phillipwood/wip/fix-checkout-p-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/262\n-- \ngitgitgadget\n"},{"id":"377054","messageId":"98d9302618aecd941eff5ea0a1e797f94769c73d.1560331526.git.gitgitgadget@gmail.com","threadId":"51294","inReplyTo":"pull.262.git.gitgitgadget@gmail.com","subject":"[PATCH 1/1] add -p: fix checkout -p with pathological context","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-06-12T09:25:27Z","receivedAt":"2019-06-12T09:25:31Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"From: Phillip Wood <phillip.wood@dunelm.org.uk>\n\nCommit fecc6f3a68 (\"add -p: adjust offsets of subsequent hunks when one is\nskipped\", 2018-03-01) fixed adding hunks in the correct place when a\nprevious hunk has been skipped. However it did not address patches that\nare applied in reverse. In that case we need to adjust the pre-image\noffset so that when apply reverses the patch the post-image offset is\nadjusted correctly. We subtract rather than add the delta as the patch\nis reversed (the easiest way to think about it is to consider a hunk of\ndeletions that is skipped - in that case we want to reduce offset so we\nneed to subtract).\n\nSigned-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n---\n git-add--interactive.perl  | 6 +++++-\n t/t3701-add-interactive.sh | 8 ++++++++\n 2 files changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 20eb81cc92..da5b4ec4bc 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -972,7 +972,11 @@ sub coalesce_overlapping_hunks {\n \t\t\tnext;\n \t\t}\n \t\tif ($ofs_delta) {\n-\t\t\t$n_ofs += $ofs_delta;\n+\t\t\tif ($patch_mode_flavour{IS_REVERSE}) {\n+\t\t\t\t$o_ofs -= $ofs_delta;\n+\t\t\t} else {\n+\t\t\t\t$n_ofs += $ofs_delta;\n+\t\t\t}\n \t\t\t$_->{TEXT}->[0] = format_hunk_header($o_ofs, $o_cnt,\n \t\t\t\t\t\t\t     $n_ofs, $n_cnt);\n \t\t}\ndiff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh\nindex 65dfbc033a..69991a3168 100755\n--- a/t/t3701-add-interactive.sh\n+++ b/t/t3701-add-interactive.sh\n@@ -639,4 +639,12 @@ test_expect_success 'add -p patch editing works with pathological context lines'\n \ttest_cmp expected-2 actual\n '\n \n+test_expect_success 'checkout -p works with pathological context lines' '\n+\ttest_write_lines a a a a a a >a &&\n+\tgit add a &&\n+\ttest_write_lines a b a b a b a b a b a > a&&\n+\ttest_write_lines s n n y q | git checkout -p &&\n+\ttest_write_lines a b a b a a b a b a >expect &&\n+\ttest_cmp expect a\n+'\n test_done\n-- \ngitgitgadget\n"}]}