Skip to content

Commit

Permalink
history: fix the workaround for bash-3.0 bug of reducing histories
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 28, 2021
1 parent 76073a9 commit 15c9133
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions make_command.sh
Expand Up @@ -361,6 +361,11 @@ function sub:scan/WA-localvar_inherit {
grc 'local [^;&|()]*"\$\{[a-zA-Z_0-9]+\[@*\]\}"'
}

function sub:scan/mistake-_ble_bash {
echo "--- $FUNCNAME ---"
grc '\(\(.*\b_ble_base\b.*\)\)'
}

function sub:scan {
if ! type grc >/dev/null; then
echo 'blesh check: grc not found. grc can be found in github.com:akinomyoga/mshex.git/' >&2
Expand Down Expand Up @@ -441,6 +446,7 @@ function sub:scan {
g'
sub:scan/eval-literal
sub:scan/WA-localvar_inherit
sub:scan/mistake-_ble_bash

sub:scan/memo-numbering
}
Expand Down
1 change: 1 addition & 0 deletions memo/ChangeLog.md
Expand Up @@ -122,6 +122,7 @@
- util: work around bash-3.0 bug `"${scal[@]/xxx}"` `#D1570` 0000000
- sabbrev (`ble-sabbrev`): fix delayed output before the initialization `#D1573` 0000000
- main: fix the workaround for `set -u` `#D1575` 0000000
- history: fix the workaround for bash-3.0 bug of reducing histories `#D1576` 0000000

## Compatibility

Expand Down
24 changes: 24 additions & 0 deletions note.txt
Expand Up @@ -4655,6 +4655,30 @@ bash_tips

2021-05-28

* history: bash-3.0 で履歴の数が減少していく問題が再発している [#D1576]

これは対策をした筈なのに何故だろうか。

取り敢えず対策コードにちゃんと進入しているのかどうかだけでも確認する。

再現条件が分かった。bashrc からロードしていると発生しないが、コマンドから
source して attach すると発生する。bash-3.1 では再現しない。

該当箇所で確認したがちゃんと復元できている様な気がする。history -p で検索し
てみたらもう一箇所別の場所で呼び出している。其処の判定条件を確認すると
bash-4.0 未満の場合には無条件でサブシェルで実行している様に見える。と思った
がよく見たら _ble_bash となるべき所が _ble_base になってしまっている。

然し、そもそもサブシェルの判定は ((BASH_SUBSHELL)) で判定できるのでこんなに
複雑な式を用いる必要はない。

* done: 算術式の中で誤って _ble_base を使ってしまうという事が余りに多いので
これも make_command.sh に登録しておくのが良い気がする。登録した。

$ grc '\(\(.*\b_ble_base\b.*\)\)'

他には同じミスをしている箇所は存在しなかった様である。

* main: set -u で壊れていないか久しぶりに確認する必要がある気がする [#D1575]

試してみたら沢山のエラーが発生している。というか本来 set +u で待避している
Expand Down
4 changes: 1 addition & 3 deletions src/history.sh
Expand Up @@ -37,9 +37,7 @@ function ble/builtin/history/is-empty {
# Note: 状況によって history -p で項目が減少するので
# サブシェルの中で評価する必要がある。
# 但し、サブシェルの中に既にいる時にはこの fork は省略できる。
# Bash 3.2 以前ではサブシェルの中にいるかどうかの判定自体に
# fork&exec が必要になるので常にサブシェルで評価する。
if ((_ble_base<40000)) || [[ $BASHPID == "$$" ]]; then
if ((!BASH_SUBSHELL)); then
(! builtin history -p '!!')
else
! builtin history -p '!!'
Expand Down

0 comments on commit 15c9133

Please sign in to comment.