{"thread":{"id":"42951","subject":"[PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count","startedAt":"2016-07-28T17:47:39Z","lastAt":"2016-07-28T20:30:30Z","messageCount":4,"participants":["Johannes Sixt","Eric Sunshine","Jakub Narębski","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"292435","messageId":"fa512576-487e-9b9c-3ada-7f0d9b135e4b@kdbg.org","threadId":"42951","inReplyTo":null,"subject":"[PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2016-07-28T17:47:23Z","receivedAt":"2016-07-28T17:47:39Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Interactive rebase uses 'wc -l' to write the current patch number\nin a progress report. Some implementations of 'wc -l' produce spaces\nbefore the number, leading to ugly output such as\n\n  Rebasing (     3/8)\n\nRemove the spaces using a trivial arithmetic evaluation.\n\nBefore 9588c52 (i18n: rebase-interactive: mark strings for\ntranslation) this was not a problem because printf was used to\ngenerate the text. Since that commit, the count is interpolated\ndirectly from a shell variable into the text, where the spaces\nremain. The total number of patches does not have this problem\neven though it is interpolated from a shell variable in the same\nmanner, because the variable is set by an arithmetic evaluation.\n\nLater in the script, there is a virtually identical case where\nleading spaces are trimmed, but it uses a pattern substitution:\n\ntodocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\ntodocount=${todocount##* }\n\nI did not choose this idiom because it adds a line of code, and\nthere is already an arithmetic evaluation in the vicinity of the\nline that is changed here.\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\n---\n git-rebase--interactive.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex ded4595..e2da524 100644\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -121,7 +121,7 @@ mark_action_done () {\n \tsed -e 1q < \"$todo\" >> \"$done\"\n \tsed -e 1d < \"$todo\" >> \"$todo\".new\n \tmv -f \"$todo\".new \"$todo\"\n-\tnew_count=$(git stripspace --strip-comments <\"$done\" | wc -l)\n+\tnew_count=$(( $(git stripspace --strip-comments <\"$done\" | wc -l) ))\n \techo $new_count >\"$msgnum\"\n \ttotal=$(($new_count + $(git stripspace --strip-comments <\"$todo\" | wc -l)))\n \techo $total >\"$end\"\n-- \n2.9.0.443.ga8520ad\n\n"},{"id":"292437","messageId":"CAPig+cSBZ_Vey2BW8S4D+7ufG1U3a-N402s4zZZJ2OE=xH1+tQ@mail.gmail.com","threadId":"42951","inReplyTo":"fa512576-487e-9b9c-3ada-7f0d9b135e4b@kdbg.org","subject":"Re: [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-07-28T18:22:03Z","receivedAt":"2016-07-28T18:22:10Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jul 28, 2016 at 1:47 PM, Johannes Sixt <j6t@kdbg.org> wrote:\n> Interactive rebase uses 'wc -l' to write the current patch number\n> in a progress report. Some implementations of 'wc -l' produce spaces\n> before the number, leading to ugly output such as\n>\n>   Rebasing (     3/8)\n>\n> Remove the spaces using a trivial arithmetic evaluation.\n>\n> Before 9588c52 (i18n: rebase-interactive: mark strings for\n> translation) this was not a problem because printf was used to\n> generate the text. Since that commit, the count is interpolated\n> directly from a shell variable into the text, where the spaces\n> remain. The total number of patches does not have this problem\n> even though it is interpolated from a shell variable in the same\n> manner, because the variable is set by an arithmetic evaluation.\n>\n> Later in the script, there is a virtually identical case where\n> leading spaces are trimmed, but it uses a pattern substitution:\n>\n> todocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\n> todocount=${todocount##* }\n>\n> I did not choose this idiom because it adds a line of code, and\n> there is already an arithmetic evaluation in the vicinity of the\n> line that is changed here.\n\nOn the other hand, to a newcomer (not familiar with this patch),\n${foo##* } is an obvious and intentional stripping of whitespace,\nwhereas taking advantage of a side-effect of arithmetic evaluation to\nachieve the same is quite subtle and likely to be interpreted as\npointless, thus forces the reader to consult 'blame' to understand why\nthe code is the way it is.\n\n> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n> ---\n> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\n> @@ -121,7 +121,7 @@ mark_action_done () {\n>         sed -e 1q < \"$todo\" >> \"$done\"\n>         sed -e 1d < \"$todo\" >> \"$todo\".new\n>         mv -f \"$todo\".new \"$todo\"\n> -       new_count=$(git stripspace --strip-comments <\"$done\" | wc -l)\n> +       new_count=$(( $(git stripspace --strip-comments <\"$done\" | wc -l) ))\n>         echo $new_count >\"$msgnum\"\n>         total=$(($new_count + $(git stripspace --strip-comments <\"$todo\" | wc -l)))\n>         echo $total >\"$end\"\n"},{"id":"292439","messageId":"579A52BD.8050009@gmail.com","threadId":"42951","inReplyTo":"CAPig+cSBZ_Vey2BW8S4D+7ufG1U3a-N402s4zZZJ2OE=xH1+tQ@mail.gmail.com","subject":"Re: [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2016-07-28T18:45:17Z","receivedAt":"2016-07-28T18:45:40Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 2016-07-28 o 20:22, Eric Sunshine pisze:\n> On Thu, Jul 28, 2016 at 1:47 PM, Johannes Sixt <j6t@kdbg.org> wrote:\n>> Interactive rebase uses 'wc -l' to write the current patch number\n>> in a progress report. Some implementations of 'wc -l' produce spaces\n>> before the number, leading to ugly output such as\n>>\n>>   Rebasing (     3/8)\n>>\n>> Remove the spaces using a trivial arithmetic evaluation.\n>>\n>> Before 9588c52 (i18n: rebase-interactive: mark strings for\n>> translation) this was not a problem because printf was used to\n>> generate the text. Since that commit, the count is interpolated\n>> directly from a shell variable into the text, where the spaces\n>> remain. The total number of patches does not have this problem\n>> even though it is interpolated from a shell variable in the same\n>> manner, because the variable is set by an arithmetic evaluation.\n>>\n>> Later in the script, there is a virtually identical case where\n>> leading spaces are trimmed, but it uses a pattern substitution:\n>>\n>> todocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\n>> todocount=${todocount##* }\n>>\n>> I did not choose this idiom because it adds a line of code, and\n>> there is already an arithmetic evaluation in the vicinity of the\n>> line that is changed here.\n> \n> On the other hand, to a newcomer (not familiar with this patch),\n> ${foo##* } is an obvious and intentional stripping of whitespace,\n> whereas taking advantage of a side-effect of arithmetic evaluation to\n> achieve the same is quite subtle and likely to be interpreted as\n> pointless, thus forces the reader to consult 'blame' to understand why\n> the code is the way it is.\n\nOn the gripping hand, the number of currently processed commits\n(instructions) in an interactive rebase is a number, and arithmetic\nexpansion can be understood as shell equivalent of casting to integer.\n\n>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n>> ---\n>> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\n>> @@ -121,7 +121,7 @@ mark_action_done () {\n>>         sed -e 1q < \"$todo\" >> \"$done\"\n>>         sed -e 1d < \"$todo\" >> \"$todo\".new\n>>         mv -f \"$todo\".new \"$todo\"\n>> -       new_count=$(git stripspace --strip-comments <\"$done\" | wc -l)\n>> +       new_count=$(( $(git stripspace --strip-comments <\"$done\" | wc -l) ))\n>>         echo $new_count >\"$msgnum\"\n>>         total=$(($new_count + $(git stripspace --strip-comments <\"$todo\" | wc -l)))\n>>         echo $total >\"$end\"\n\n"},{"id":"292450","messageId":"xmqqpopxqze2.fsf@gitster.mtv.corp.google.com","threadId":"42951","inReplyTo":"579A52BD.8050009@gmail.com","subject":"Re: [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-07-28T20:30:13Z","receivedAt":"2016-07-28T20:30:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narębski <jnareb@gmail.com> writes:\n\n> On the gripping hand, the number of currently processed commits\n> (instructions) in an interactive rebase is a number, and arithmetic\n> expansion can be understood as shell equivalent of casting to integer.\n\nI get that argument; it is a bit too cute a justification for my\ntaste, but the resulting code is consistent with how $total loses\nthe potential leading whitespace, so I'll queue it as-is.\n\nThanks.\n\n>\n>>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n>>> ---\n>>> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\n>>> @@ -121,7 +121,7 @@ mark_action_done () {\n>>>         sed -e 1q < \"$todo\" >> \"$done\"\n>>>         sed -e 1d < \"$todo\" >> \"$todo\".new\n>>>         mv -f \"$todo\".new \"$todo\"\n>>> -       new_count=$(git stripspace --strip-comments <\"$done\" | wc -l)\n>>> +       new_count=$(( $(git stripspace --strip-comments <\"$done\" | wc -l) ))\n>>>         echo $new_count >\"$msgnum\"\n>>>         total=$(($new_count + $(git stripspace --strip-comments <\"$todo\" | wc -l)))\n>>>         echo $total >\"$end\"\n"}]}