{"thread":{"id":"24471","subject":"[PATCH] git-rebase--interactive.sh: use printf instead of echo to print commit message","startedAt":"2010-07-22T19:15:11Z","lastAt":"2010-07-22T20:08:25Z","messageCount":3,"participants":["Brandon Casey","Jonathan Nieder","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"146010","messageId":"MoU2SrLLcYS4J28tNBJjfxYnqoLoX04XwHLgciB5KCUnhqJoXifmNFbSGHS4r8pboBurx-NhZWs@cipher.nrlssc.navy.mil","threadId":"24471","inReplyTo":null,"subject":"[PATCH] git-rebase--interactive.sh: use printf instead of echo to print commit message","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2010-07-22T19:15:11Z","receivedAt":"2010-07-22T19:15:11Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nOn systems with an echo which defaults to the XSI-conformant behavior\n(Solaris, or others using Ksh), echo will interpret certain backslashed\ncharacters as control sequences.  This can cause a problem for interactive\nrebase when it is used to rebase commits whose commit \"subject\" (the first\nline) contains any of these backslashed sequences.  In this case, echo will\nsubstitute the control sequence for the backslashed characters and either\nthe rebased commit message will differ from the original, or the rebase\nprocess will fail.  Neither is desirable.\n\nSo work around this issue by replacing the echo statements used to print\nout portions of the commit message, with printf.\n\nAlso, add a test to test for this breakage.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n git-rebase--interactive.sh    |   12 ++++++------\n t/t3404-rebase-interactive.sh |    8 +++++++-\n 2 files changed, 13 insertions(+), 7 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 31e6860..b94c2a0 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -119,7 +119,7 @@ run 'git rebase --continue'\"\n export GIT_CHERRY_PICK_HELP\n \n warn () {\n-\techo \"$*\" >&2\n+\tprintf '%s\\n' \"$*\" >&2\n }\n \n output () {\n@@ -606,7 +606,7 @@ skip_unnecessary_picks () {\n \t\t\tfd=1\n \t\t\t;;\n \t\tesac\n-\t\techo \"$command${sha1:+ }$sha1${rest:+ }$rest\" >&$fd\n+\t\tprintf '%s\\n' \"$command${sha1:+ }$sha1${rest:+ }$rest\" >&$fd\n \tdone <\"$TODO\" >\"$TODO.new\" 3>>\"$DONE\" &&\n \tmv -f \"$TODO\".new \"$TODO\" &&\n \tcase \"$(peek_next_command)\" in\n@@ -649,12 +649,12 @@ rearrange_squash () {\n \t\tcase \" $used\" in\n \t\t*\" $sha1 \"*) continue ;;\n \t\tesac\n-\t\techo \"$pick $sha1 $message\"\n+\t\tprintf '%s\\n' \"$pick $sha1 $message\"\n \t\twhile read -r squash action msg\n \t\tdo\n \t\t\tcase \"$message\" in\n \t\t\t\"$msg\"*)\n-\t\t\t\techo \"$action $squash $action! $msg\"\n+\t\t\t\tprintf '%s\\n' \"$action $squash $action! $msg\"\n \t\t\t\tused=\"$used$squash \"\n \t\t\t\t;;\n \t\t\tesac\n@@ -895,7 +895,7 @@ first and then run 'git rebase --continue' again.\"\n \t\tdo\n \t\t\tif test t != \"$PRESERVE_MERGES\"\n \t\t\tthen\n-\t\t\t\techo \"pick $shortsha1 $rest\" >> \"$TODO\"\n+\t\t\t\tprintf '%s\\n' \"pick $shortsha1 $rest\" >> \"$TODO\"\n \t\t\telse\n \t\t\t\tsha1=$(git rev-parse $shortsha1)\n \t\t\t\tif test -z \"$REBASE_ROOT\"\n@@ -914,7 +914,7 @@ first and then run 'git rebase --continue' again.\"\n \t\t\t\tif test f = \"$preserve\"\n \t\t\t\tthen\n \t\t\t\t\ttouch \"$REWRITTEN\"/$sha1\n-\t\t\t\t\techo \"pick $shortsha1 $rest\" >> \"$TODO\"\n+\t\t\t\t\tprintf '%s\\n' \"pick $shortsha1 $rest\" >> \"$TODO\"\n \t\t\t\tfi\n \t\t\tfi\n \t\tdone\ndiff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh\nindex 47ca88f..9f03ce6 100755\n--- a/t/t3404-rebase-interactive.sh\n+++ b/t/t3404-rebase-interactive.sh\n@@ -637,13 +637,19 @@ test_expect_success 'set up commits with funny messages' '\n \tgit commit -a -m \"end with slash\\\\\" &&\n \techo >>file1 &&\n \ttest_tick &&\n+\tgit commit -a -m \"something (\\000) that looks like octal\" &&\n+\techo >>file1 &&\n+\ttest_tick &&\n+\tgit commit -a -m \"something (\\n) that looks like a newline\" &&\n+\techo >>file1 &&\n+\ttest_tick &&\n \tgit commit -a -m \"another commit\"\n '\n \n test_expect_success 'rebase-i history with funny messages' '\n \tgit rev-list A..funny >expect &&\n \ttest_tick &&\n-\tFAKE_LINES=\"1 2\" git rebase -i A &&\n+\tFAKE_LINES=\"1 2 3 4\" git rebase -i A &&\n \tgit rev-list A.. >actual &&\n \ttest_cmp expect actual\n '\n-- \n1.7.2.1.g1787a\n"},{"id":"146012","messageId":"20100722194549.GA4439@burratino","threadId":"24471","inReplyTo":"MoU2SrLLcYS4J28tNBJjfxYnqoLoX04XwHLgciB5KCUnhqJoXifmNFbSGHS4r8pboBurx-NhZWs@cipher.nrlssc.navy.mil","subject":"Re: [PATCH] git-rebase--interactive.sh: use printf instead of echo to print commit message","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-07-22T19:45:49Z","receivedAt":"2010-07-22T19:45:49Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Brandon Casey wrote:\n\n> On systems with an echo which defaults to the XSI-conformant behavior\n> (Solaris, or others using Ksh)\n\nDebian and BSD systems with the Almquist shell, too.\n\n> So work around this issue by replacing the echo statements used to print\n> out portions of the commit message, with printf.\n\nAcked-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThanks for taking care of this.\n"},{"id":"146016","messageId":"AANLkTinBvIE-nW__qN9XpbWiwhx1C6_FWylWQRLGd2BQ@mail.gmail.com","threadId":"24471","inReplyTo":"MoU2SrLLcYS4J28tNBJjfxYnqoLoX04XwHLgciB5KCUnhqJoXifmNFbSGHS4r8pboBurx-NhZWs@cipher.nrlssc.navy.mil","subject":"Re: [PATCH] git-rebase--interactive.sh: use printf instead of echo to print commit message","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-22T20:08:25Z","receivedAt":"2010-07-22T20:08:25Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Jul 22, 2010 at 19:15, Brandon Casey <casey@nrlssc.navy.mil> wrote:\n> From: Brandon Casey <drafnel@gmail.com>\n>\n> On systems with an echo which defaults to the XSI-conformant behavior\n> (Solaris, or others using Ksh), echo will interpret certain backslashed\n> characters as control sequences.  This can cause a problem for interactive\n> rebase when it is used to rebase commits whose commit \"subject\" (the first\n> line) contains any of these backslashed sequences.  In this case, echo will\n> substitute the control sequence for the backslashed characters and either\n> the rebased commit message will differ from the original, or the rebase\n> process will fail.  Neither is desirable.\n>\n> So work around this issue by replacing the echo statements used to print\n> out portions of the commit message, with printf.\n>\n> Also, add a test to test for this breakage.\n\nThis looks good, especially the test for it:\n\nAcked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"}]}