All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count
@ 2016-07-28 17:47 Johannes Sixt
  2016-07-28 18:22 ` Eric Sunshine
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2016-07-28 17:47 UTC (permalink / raw)
  To: Vasco Almeida; +Cc: Git Mailing List

Interactive rebase uses 'wc -l' to write the current patch number
in a progress report. Some implementations of 'wc -l' produce spaces
before the number, leading to ugly output such as

  Rebasing (     3/8)

Remove the spaces using a trivial arithmetic evaluation.

Before 9588c52 (i18n: rebase-interactive: mark strings for
translation) this was not a problem because printf was used to
generate the text. Since that commit, the count is interpolated
directly from a shell variable into the text, where the spaces
remain. The total number of patches does not have this problem
even though it is interpolated from a shell variable in the same
manner, because the variable is set by an arithmetic evaluation.

Later in the script, there is a virtually identical case where
leading spaces are trimmed, but it uses a pattern substitution:

todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
todocount=${todocount##* }

I did not choose this idiom because it adds a line of code, and
there is already an arithmetic evaluation in the vicinity of the
line that is changed here.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 git-rebase--interactive.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index ded4595..e2da524 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -121,7 +121,7 @@ mark_action_done () {
 	sed -e 1q < "$todo" >> "$done"
 	sed -e 1d < "$todo" >> "$todo".new
 	mv -f "$todo".new "$todo"
-	new_count=$(git stripspace --strip-comments <"$done" | wc -l)
+	new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
 	echo $new_count >"$msgnum"
 	total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
 	echo $total >"$end"
-- 
2.9.0.443.ga8520ad


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

* Re: [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count
  2016-07-28 17:47 [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count Johannes Sixt
@ 2016-07-28 18:22 ` Eric Sunshine
  2016-07-28 18:45   ` Jakub Narębski
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Sunshine @ 2016-07-28 18:22 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Vasco Almeida, Git Mailing List

On Thu, Jul 28, 2016 at 1:47 PM, Johannes Sixt <j6t@kdbg.org> wrote:
> Interactive rebase uses 'wc -l' to write the current patch number
> in a progress report. Some implementations of 'wc -l' produce spaces
> before the number, leading to ugly output such as
>
>   Rebasing (     3/8)
>
> Remove the spaces using a trivial arithmetic evaluation.
>
> Before 9588c52 (i18n: rebase-interactive: mark strings for
> translation) this was not a problem because printf was used to
> generate the text. Since that commit, the count is interpolated
> directly from a shell variable into the text, where the spaces
> remain. The total number of patches does not have this problem
> even though it is interpolated from a shell variable in the same
> manner, because the variable is set by an arithmetic evaluation.
>
> Later in the script, there is a virtually identical case where
> leading spaces are trimmed, but it uses a pattern substitution:
>
> todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
> todocount=${todocount##* }
>
> I did not choose this idiom because it adds a line of code, and
> there is already an arithmetic evaluation in the vicinity of the
> line that is changed here.

On the other hand, to a newcomer (not familiar with this patch),
${foo##* } is an obvious and intentional stripping of whitespace,
whereas taking advantage of a side-effect of arithmetic evaluation to
achieve the same is quite subtle and likely to be interpreted as
pointless, thus forces the reader to consult 'blame' to understand why
the code is the way it is.

> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> @@ -121,7 +121,7 @@ mark_action_done () {
>         sed -e 1q < "$todo" >> "$done"
>         sed -e 1d < "$todo" >> "$todo".new
>         mv -f "$todo".new "$todo"
> -       new_count=$(git stripspace --strip-comments <"$done" | wc -l)
> +       new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
>         echo $new_count >"$msgnum"
>         total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
>         echo $total >"$end"

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

* Re: [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count
  2016-07-28 18:22 ` Eric Sunshine
@ 2016-07-28 18:45   ` Jakub Narębski
  2016-07-28 20:30     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Narębski @ 2016-07-28 18:45 UTC (permalink / raw)
  To: Eric Sunshine, Johannes Sixt; +Cc: Vasco Almeida, Git Mailing List

W dniu 2016-07-28 o 20:22, Eric Sunshine pisze:
> On Thu, Jul 28, 2016 at 1:47 PM, Johannes Sixt <j6t@kdbg.org> wrote:
>> Interactive rebase uses 'wc -l' to write the current patch number
>> in a progress report. Some implementations of 'wc -l' produce spaces
>> before the number, leading to ugly output such as
>>
>>   Rebasing (     3/8)
>>
>> Remove the spaces using a trivial arithmetic evaluation.
>>
>> Before 9588c52 (i18n: rebase-interactive: mark strings for
>> translation) this was not a problem because printf was used to
>> generate the text. Since that commit, the count is interpolated
>> directly from a shell variable into the text, where the spaces
>> remain. The total number of patches does not have this problem
>> even though it is interpolated from a shell variable in the same
>> manner, because the variable is set by an arithmetic evaluation.
>>
>> Later in the script, there is a virtually identical case where
>> leading spaces are trimmed, but it uses a pattern substitution:
>>
>> todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
>> todocount=${todocount##* }
>>
>> I did not choose this idiom because it adds a line of code, and
>> there is already an arithmetic evaluation in the vicinity of the
>> line that is changed here.
> 
> On the other hand, to a newcomer (not familiar with this patch),
> ${foo##* } is an obvious and intentional stripping of whitespace,
> whereas taking advantage of a side-effect of arithmetic evaluation to
> achieve the same is quite subtle and likely to be interpreted as
> pointless, thus forces the reader to consult 'blame' to understand why
> the code is the way it is.

On the gripping hand, the number of currently processed commits
(instructions) in an interactive rebase is a number, and arithmetic
expansion can be understood as shell equivalent of casting to integer.

>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
>> ---
>> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
>> @@ -121,7 +121,7 @@ mark_action_done () {
>>         sed -e 1q < "$todo" >> "$done"
>>         sed -e 1d < "$todo" >> "$todo".new
>>         mv -f "$todo".new "$todo"
>> -       new_count=$(git stripspace --strip-comments <"$done" | wc -l)
>> +       new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
>>         echo $new_count >"$msgnum"
>>         total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
>>         echo $total >"$end"


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

* Re: [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count
  2016-07-28 18:45   ` Jakub Narębski
@ 2016-07-28 20:30     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2016-07-28 20:30 UTC (permalink / raw)
  To: Jakub Narębski
  Cc: Eric Sunshine, Johannes Sixt, Vasco Almeida, Git Mailing List

Jakub Narębski <jnareb@gmail.com> writes:

> On the gripping hand, the number of currently processed commits
> (instructions) in an interactive rebase is a number, and arithmetic
> expansion can be understood as shell equivalent of casting to integer.

I get that argument; it is a bit too cute a justification for my
taste, but the resulting code is consistent with how $total loses
the potential leading whitespace, so I'll queue it as-is.

Thanks.

>
>>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
>>> ---
>>> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
>>> @@ -121,7 +121,7 @@ mark_action_done () {
>>>         sed -e 1q < "$todo" >> "$done"
>>>         sed -e 1d < "$todo" >> "$todo".new
>>>         mv -f "$todo".new "$todo"
>>> -       new_count=$(git stripspace --strip-comments <"$done" | wc -l)
>>> +       new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
>>>         echo $new_count >"$msgnum"
>>>         total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
>>>         echo $total >"$end"

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

end of thread, other threads:[~2016-07-28 20:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-28 17:47 [PATCH va/i18n-even-more] rebase-interactive: trim leading whitespace from progress count Johannes Sixt
2016-07-28 18:22 ` Eric Sunshine
2016-07-28 18:45   ` Jakub Narębski
2016-07-28 20:30     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.