git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* [PATCH 0/1] add -p: fix checkout -p with pathological context
@ 2019-06-12  9:25 Phillip Wood via GitGitGadget
  2019-06-12  9:25 ` [PATCH 1/1] " Phillip Wood via GitGitGadget
  0 siblings, 1 reply; 2+ messages in thread
From: Phillip Wood via GitGitGadget @ 2019-06-12  9:25 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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.

Phillip Wood (1):
  add -p: fix checkout -p with pathological context

 git-add--interactive.perl  | 6 +++++-
 t/t3701-add-interactive.sh | 8 ++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)


base-commit: aeb582a98374c094361cba1bd756dc6307432c42
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-262%2Fphillipwood%2Fwip%2Ffix-checkout-p-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-262/phillipwood/wip/fix-checkout-p-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/262
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] add -p: fix checkout -p with pathological context
  2019-06-12  9:25 [PATCH 0/1] add -p: fix checkout -p with pathological context Phillip Wood via GitGitGadget
@ 2019-06-12  9:25 ` " Phillip Wood via GitGitGadget
  0 siblings, 0 replies; 2+ messages in thread
From: Phillip Wood via GitGitGadget @ 2019-06-12  9:25 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Commit fecc6f3a68 ("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 <phillip.wood@dunelm.org.uk>
---
 git-add--interactive.perl  | 6 +++++-
 t/t3701-add-interactive.sh | 8 ++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 20eb81cc92..da5b4ec4bc 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -972,7 +972,11 @@ sub coalesce_overlapping_hunks {
 			next;
 		}
 		if ($ofs_delta) {
-			$n_ofs += $ofs_delta;
+			if ($patch_mode_flavour{IS_REVERSE}) {
+				$o_ofs -= $ofs_delta;
+			} else {
+				$n_ofs += $ofs_delta;
+			}
 			$_->{TEXT}->[0] = format_hunk_header($o_ofs, $o_cnt,
 							     $n_ofs, $n_cnt);
 		}
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 65dfbc033a..69991a3168 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -639,4 +639,12 @@ test_expect_success 'add -p patch editing works with pathological context lines'
 	test_cmp expected-2 actual
 '
 
+test_expect_success 'checkout -p works with pathological context lines' '
+	test_write_lines a a a a a a >a &&
+	git add a &&
+	test_write_lines a b a b a b a b a b a > a&&
+	test_write_lines s n n y q | git checkout -p &&
+	test_write_lines a b a b a a b a b a >expect &&
+	test_cmp expect a
+'
 test_done
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12  9:25 [PATCH 0/1] add -p: fix checkout -p with pathological context Phillip Wood via GitGitGadget
2019-06-12  9:25 ` [PATCH 1/1] " Phillip Wood via GitGitGadget

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox