{"thread":{"id":"27228","subject":"[PATCH 0/3] Return of \"add -p [E]dit\" fix","startedAt":"2011-04-29T22:49:30Z","lastAt":"2011-04-29T22:49:33Z","messageCount":4,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"166786","messageId":"1304117373-592-1-git-send-email-gitster@pobox.com","threadId":"27228","inReplyTo":null,"subject":"[PATCH 0/3] Return of \"add -p [E]dit\" fix","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-29T22:49:30Z","receivedAt":"2011-04-29T22:49:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I kept this in the stalled state for too long.  Resending with tests\nto move the topic forward.\n\nJunio C Hamano (3):\n  t3701: Editing a split hunk in an \"add -p\" session\n  add--interactive.perl: factor out repeated --recount option\n  \"add -p\": work-around an old laziness that does not coalesce hunks\n\n builtin/apply.c            |    9 ++++++---\n git-add--interactive.perl  |   16 ++++++++--------\n t/t3701-add-interactive.sh |   36 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 50 insertions(+), 11 deletions(-)\n\n-- \n1.7.5.252.g565191\n"},{"id":"166787","messageId":"1304117373-592-2-git-send-email-gitster@pobox.com","threadId":"27228","inReplyTo":"1304117373-592-1-git-send-email-gitster@pobox.com","subject":"[PATCH 1/3] t3701: Editing a split hunk in an \"add -p\" session","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-29T22:49:31Z","receivedAt":"2011-04-29T22:49:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Arnaud Lacombe reported that with the recent change to reject overlapping\nhunks fed to \"git apply\", the edit mode of an \"add -p\" session that lazily\nfeeds overlapping hunks without coalescing adjacent ones claim that the\npatch does not apply.  Expose the problem to be fixed.\n\nCf. http://thread.gmane.org/gmane.comp.version-control.git/170685/focus=171000\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t3701-add-interactive.sh |   36 ++++++++++++++++++++++++++++++++++++\n 1 files changed, 36 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh\nindex d6327e7..72559e1 100755\n--- a/t/t3701-add-interactive.sh\n+++ b/t/t3701-add-interactive.sh\n@@ -295,4 +295,40 @@ test_expect_success PERL 'deleting an empty file' '\n \ttest_cmp expected diff\n '\n \n+test_expect_success PERL 'split hunk setup' '\n+\tgit reset --hard &&\n+\tfor i in 10 20 30 40 50 60\n+\tdo\n+\t\techo $i\n+\tdone >test &&\n+\tgit add test &&\n+\ttest_tick &&\n+\tgit commit -m test &&\n+\n+\tfor i in 10 15 20 21 22 23 24 30 40 50 60\n+\tdo\n+\t\techo $i\n+\tdone >test\n+'\n+\n+test_expect_failure PERL 'split hunk \"add -p (edit)\"' '\n+\t# Split, say Edit and do nothing.  Then:\n+\t#\n+\t# 1. Broken version results in a patch that does not apply and\n+\t# only takes [y/n] (edit again) so the first q is discarded\n+\t# and then n attempts to discard the edit. Repeat q enough\n+\t# times to get out.\n+\t#\n+\t# 2. Correct version applies the (not)edited version, and asks\n+\t#    about the next hunk, against wich we say q and program\n+\t#    exits.\n+\tfor a in s e     q n q q\n+\tdo\n+\t\techo $a\n+\tdone |\n+\tEDITOR=: git add -p &&\n+\tgit diff >actual &&\n+\t! grep \"^+15\" actual\n+'\n+\n test_done\n-- \n1.7.5.252.g565191\n"},{"id":"166788","messageId":"1304117373-592-3-git-send-email-gitster@pobox.com","threadId":"27228","inReplyTo":"1304117373-592-1-git-send-email-gitster@pobox.com","subject":"[PATCH 2/3] add--interactive.perl: factor out repeated --recount option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-29T22:49:32Z","receivedAt":"2011-04-29T22:49:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Depending on the direction and the target of patch application, we would\nneed to pass --cached and --reverse to underlying \"git apply\".  Also we\nonly pass --check when we are not applying but just checking.\n\nBut we always pass --recount since 8cbd431 (git-add--interactive: replace\nhunk recounting with apply --recount, 2008-07-02).  Instead of repeating\nthe same --recount over and over again, move it to a single place that\nactually runs the command, namely, \"run_git_apply\" subroutine.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-add--interactive.perl |   16 ++++++++--------\n 1 files changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 4fb8cd0..fced0ce 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -705,7 +705,7 @@ sub add_untracked_cmd {\n sub run_git_apply {\n \tmy $cmd = shift;\n \tmy $fh;\n-\topen $fh, '| git ' . $cmd;\n+\topen $fh, '| git ' . $cmd . \" --recount\";\n \tprint $fh @_;\n \treturn close $fh;\n }\n@@ -1050,7 +1050,7 @@ sub edit_hunk_manually {\n \n sub diff_applies {\n \tmy $fh;\n-\treturn run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --recount --check',\n+\treturn run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --check',\n \t\t\t     map { @{$_->{TEXT}} } @_);\n }\n \n@@ -1139,7 +1139,7 @@ sub help_patch_cmd {\n \n sub apply_patch {\n \tmy $cmd = shift;\n-\tmy $ret = run_git_apply $cmd . ' --recount', @_;\n+\tmy $ret = run_git_apply $cmd, @_;\n \tif (!$ret) {\n \t\tprint STDERR @_;\n \t}\n@@ -1148,17 +1148,17 @@ sub apply_patch {\n \n sub apply_patch_for_checkout_commit {\n \tmy $reverse = shift;\n-\tmy $applies_index = run_git_apply 'apply '.$reverse.' --cached --recount --check', @_;\n-\tmy $applies_worktree = run_git_apply 'apply '.$reverse.' --recount --check', @_;\n+\tmy $applies_index = run_git_apply 'apply '.$reverse.' --cached --check', @_;\n+\tmy $applies_worktree = run_git_apply 'apply '.$reverse.' --check', @_;\n \n \tif ($applies_worktree && $applies_index) {\n-\t\trun_git_apply 'apply '.$reverse.' --cached --recount', @_;\n-\t\trun_git_apply 'apply '.$reverse.' --recount', @_;\n+\t\trun_git_apply 'apply '.$reverse.' --cached', @_;\n+\t\trun_git_apply 'apply '.$reverse, @_;\n \t\treturn 1;\n \t} elsif (!$applies_index) {\n \t\tprint colored $error_color, \"The selected hunks do not apply to the index!\\n\";\n \t\tif (prompt_yesno \"Apply them to the worktree anyway? \") {\n-\t\t\treturn run_git_apply 'apply '.$reverse.' --recount', @_;\n+\t\t\treturn run_git_apply 'apply '.$reverse, @_;\n \t\t} else {\n \t\t\tprint colored $error_color, \"Nothing was applied.\\n\";\n \t\t\treturn 0;\n-- \n1.7.5.252.g565191\n"},{"id":"166789","messageId":"1304117373-592-4-git-send-email-gitster@pobox.com","threadId":"27228","inReplyTo":"1304117373-592-1-git-send-email-gitster@pobox.com","subject":"[PATCH 3/3] \"add -p\": work-around an old laziness that does not coalesce hunks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-29T22:49:33Z","receivedAt":"2011-04-29T22:49:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Since 0beee4c (git-add--interactive: remove hunk coalescing, 2008-07-02),\n\"git add--interactive\" behaves lazily and passes overlapping hunks to the\nunderlying \"git apply\" without coalescing.  This was partially corrected\nby 7a26e65 (its partial revert, 2009-05-16), but overlapping hunks are\nstill passed when the patch is edited.\n\nTeach \"git apply\" the --allow-overlap option that disables a safety\nfeature that avoids misapplication of patches by not applying patches\nto overlapping hunks, and pass this option form \"add -p\" codepath.\n\nDo not even advertise the option, as this is merely a workaround, and the\ncorrect fix is to make \"add -p\" correctly coalesce adjacent patch hunks.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/apply.c           |    9 ++++++---\n git-add--interactive.perl |    2 +-\n 2 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 04f56f8..8be1ce5 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -43,6 +43,7 @@ static int apply = 1;\n static int apply_in_reverse;\n static int apply_with_reject;\n static int apply_verbosely;\n+static int allow_overlap;\n static int no_add;\n static const char *fake_ancestor;\n static int line_termination = '\\n';\n@@ -2430,9 +2431,9 @@ static void update_image(struct image *img,\n \tmemcpy(img->line + applied_pos,\n \t       postimage->line,\n \t       postimage->nr * sizeof(*img->line));\n-\tfor (i = 0; i < postimage->nr; i++)\n-\t\timg->line[applied_pos + i].flag |= LINE_PATCHED;\n-\n+\tif (!allow_overlap)\n+\t\tfor (i = 0; i < postimage->nr; i++)\n+\t\t\timg->line[applied_pos + i].flag |= LINE_PATCHED;\n \timg->nr = nr;\n }\n \n@@ -3877,6 +3878,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)\n \t\t\t\"don't expect at least one line of context\"),\n \t\tOPT_BOOLEAN(0, \"reject\", &apply_with_reject,\n \t\t\t\"leave the rejected hunks in corresponding *.rej files\"),\n+\t\tOPT_BOOLEAN(0, \"allow-overlap\", &allow_overlap,\n+\t\t\t\"allow overlapping hunks\"),\n \t\tOPT__VERBOSE(&apply_verbosely, \"be verbose\"),\n \t\tOPT_BIT(0, \"inaccurate-eof\", &options,\n \t\t\t\"tolerate incorrectly detected missing new-line at the end of file\",\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex fced0ce..4f08fe7 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -705,7 +705,7 @@ sub add_untracked_cmd {\n sub run_git_apply {\n \tmy $cmd = shift;\n \tmy $fh;\n-\topen $fh, '| git ' . $cmd . \" --recount\";\n+\topen $fh, '| git ' . $cmd . \" --recount --allow-overlap\";\n \tprint $fh @_;\n \treturn close $fh;\n }\n-- \n1.7.5.252.g565191\n"}]}